我正在编写一些默认动画,只有当 4 个按钮都没有悬停 1 秒时才会触发。
如果在等待期间(即 1 秒)悬停任何按钮,则计时器应重置。任何的想法?谢谢!
[更新] 在下面的评论中查看我的片段,希望有人觉得它有用。
我正在编写一些默认动画,只有当 4 个按钮都没有悬停 1 秒时才会触发。
如果在等待期间(即 1 秒)悬停任何按钮,则计时器应重置。任何的想法?谢谢!
[更新] 在下面的评论中查看我的片段,希望有人觉得它有用。
尝试
$(function() {
var timer;
function schedule() {
timer = setTimeout(function() {
// start timer
}, 1000);
};
$('button').hover(function() {
if (timer) {
clearTimeout(timer);
}
}, function() {
schedule();
});
schedule();
});
演示:小提琴
假设每个按钮都有一个类'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);
});