2012-10-02 41 views
0
$(document).ready(function() { 
    var timer; 

    var click = function() { 
     $('div button').trigger('click'); 
    } 

    $('div button').click(function(){ 
     //animation 
    } 

    $('div').live('mouseover mouseout', function(event) { 

     if (event.type == 'mouseover') { 
      clearInterval(timer); 
     } 
     else { 
      timer = setInterval(click, 1000); 

     } 
    }); 
}); 

正如你在上面看到的,我試圖在mouseout時做一個setInterval工作並在mouseover時停止。代碼目前正在運行,但是頁面加載後動畫不會啓動。 所以,現在你必須將鼠標懸停在div,mouseout之後,動畫纔會開始。
如何更改它?setInterval mouseout和mouseover

+0

後只需添加觸發你可能引發的setInterval在$(文件)。就緒,然後立即將其清除。 – trickyzter

+1

或者只需在'$(document).ready'的末尾調用'click()'。 – Bill

+0

更有意義。 :) – trickyzter

回答

0

結合

$('div button').click(function(){ 
    //animation 
}.trigger('click')