0

我正在研究 jQuery 函数,我有一个在触发 mouseover 事件时工作的函数,但我的要求是它不应该在鼠标悬停时调用,它应该每 5 秒调用一次,但我无法实现这一点。如何解决这个问题?

我已经添加了片段供您参考..

f.children(a.childSelector).each(function(h) {
        jQuery(this).mouseover(function(i) {
                var j = (a.reflect === true) ? 360 - (g * h) : g * h;
            j = jQuery.roundabout_toFloat(j);
            if (!jQuery.roundabout_isInFocus(f, j)) {
                i.preventDefault();
                if (f.data("roundabout").animating === 0) {
                    f.roundabout_animateAngleToFocus(j)
                }
                return false
            }
        })  
})
4

3 回答 3

0

看看 jQuery-Timers: http: //archive.plugins.jquery.com/project/timers

$(document).everyTime(1000, "tag", function(i) { // every 1000ms
   // do something
}, 200); // 200 times
于 2012-08-28T21:09:33.467 回答
0
var repeatFunction = setInterval(function(){
    //do something here
}, 5000); //repeats after interval of 5 second (atleast)
于 2012-08-28T06:33:34.397 回答
0

it should call every 5 seconds

Use setInterval(..) or for more flexibility imitate the functionality using setTimeout(..).

Something like:

f.children(a.childSelector).each(function(h) {
        setInterval(function() {
            var j = (a.reflect === true) ? 360 - (g * h) : g * h;
            j = jQuery.roundabout_toFloat(j);
            if (!jQuery.roundabout_isInFocus(f, j)) {
                if (f.data("roundabout").animating === 0) {
                    f.roundabout_animateAngleToFocus(j)
                }
            }
        },5000);  
    })
于 2012-08-28T06:34:06.720 回答