我正在做jQuery函数的工作,我有一个函数在触发鼠标悬停事件时工作,但我的要求是它不应该在鼠标悬停时调用,它应该每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
}
})
})
var repeatFunction = setInterval(function(){
//do something here
}, 5000); //repeats after interval of 5 second (atleast)
它应该每5秒调用一次
使用setInterval(..)
或为了获得更大的灵活性,模仿使用setTimeout(..)
的功能。
类似于:
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);
})
看看jQuery Timers:http://archive.plugins.jquery.com/project/timers
$(document).everyTime(1000, "tag", function(i) { // every 1000ms
// do something
}, 200); // 200 times