2013-04-23 72 views
0

我正在寫一些默認動畫,只有當4個按鈕都沒有被徘徊1秒時纔會觸發。

如果在等待期間(即1秒)內任何按鈕懸停,計時器應重置。任何想法?謝謝!jQuery - 觸發一段時間的元素「取消」時觸發事件

[更新] 在下面的評論中看到我的片段,希望有人認爲它有用。

+0

你有什麼/試過嗎?我們很有幫助,但我們不是通靈。 – George 2013-04-23 10:04:46

+0

對不起:P – 2013-04-23 16:15:30

+0

http://jsfiddle.net/monkichik/wAUBQ/ – 2013-04-23 16:19:10

回答

1

嘗試

$(function() { 
    var timer; 

    function schedule() { 
     timer = setTimeout(function() { 
      // start timer 
     }, 1000); 
    }; 

    $('button').hover(function() { 
     if (timer) { 
      clearTimeout(timer); 
     } 
    }, function() { 
     schedule(); 
    }); 
    schedule(); 
}); 

演示:Fiddle

+0

驚人的,成功地合併到我的代碼中,謝謝! – 2013-04-23 10:54:12

+0

http://jsfiddle.net/monkichik/wAUBQ – 2013-04-23 16:24:54

+0

@ MONKICHI.K.KICHI good work – 2013-04-23 16:35:08

0

假設每個按鈕都有一個類的BTN「

$(".btn").bind('onmouseenter',function(){ 
//Clear the Timer 
    window.clearInterval(); 

//count the timer and write the logic 
    window.setInterval(function(){ 
    //Logic of Animation you are gonna do if no hovering happens in 1 sec 
},1000); 
});