0

我正在编写一些默认动画,只有当 4 个按钮都没有悬停 1 秒时才会触发。

如果在等待期间(即 1 秒)悬停任何按钮,则计时器应重置。任何的想法?谢谢!

[更新] 在下面的评论中查看我的片段,希望有人觉得它有用。

4

2 回答 2

1

尝试

$(function() {
    var timer;

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

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

演示:小提琴

于 2013-04-23T10:25:25.120 回答
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);
});
于 2013-04-23T10:24:59.507 回答