2012-08-28 25 views
0

我正在做jQuery函數工作,我有一個函數在mouseover事件觸發時工作,但我的要求是它不應該在鼠標懸停時調用,它應該每5秒調用一次,但是我不能沒有達到這個目標。如何解決這個問題?jquery定時器函數

我已經添加了片段供大家參考..

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 
      } 
     }) 
}) 
+0

給一些HTML代碼爲好,這樣我們就可以複製的問題 – ShaunOReilly

回答

0
var repeatFunction = setInterval(function(){ 
    //do something here 
}, 5000); //repeats after interval of 5 second (atleast) 
0

應該每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); 
    })