我正在寻找一个包含所有图像的数组,然后我想为一个随机图像分配一个介于1到10之间的值。它最终得到的值是一个以秒为单位的倒计时,直到运行Jquery动画为止。然后,代码将一遍又一遍地循环,直到该人离开该页面为止。

因此,我是Jquery的新手,但是我尽力了结,因此这是我的图像数组和随机选择器;

var iconImgs = new Array('star','coffee','picture','code');
var max = iconImgs.length;
var num = Math.floor((Math.random() * max));


然后,我需要选择1-10之间的随机时间;

Math.floor((Math.random()*10)+1);


这是我需要拍摄的难点,需要随机的时间将它们放在一起,然后运行动画(请注意,我不希望它开始运行,但这是我获得效果的唯一方法)。

$(document).ready(function () {
$(".icon").mouseenter(function () {
    $(this).effect("bounce", {
        times: 1
    }, 400);
    });
});


我做了一个JSFiddle测试区域-http://jsfiddle.net/UQTY2/167/

最佳答案

尝试这个

var iconImgs = new Array('star','coffee','picture','code');
var max = iconImgs.length;
var times = Math.floor((Math.random()*10)+1);

$(document).ready(function () {

    setInterval(function () {
        var num = Math.floor((Math.random() * max));

        $("."+iconImgs[num]+"-icon").effect("bounce", {
            times: times
        }, 400);
    }, 400);

});


JSFIDDLE:
http://jsfiddle.net/UQTY2/168/

09-17 15:22
查看更多