$('.file a').live('mouseenter', function() {
$('#download').stop(true, true).fadeIn('fast');
}).live('mouseleave', function() {
$('#download').stop(true, true).fadeOut('fast');
});
我希望 mouseenter
函数有一个 stop()
和 1 秒的延迟.因此,如果我将鼠标悬停在 #download
上,则 fadeIn
应该会在 1 秒延迟后开始.如果我同时鼠标移出 fadeIn
不应该启动.找我?
I want the mouseenter
function to have a stop()
and a delay of 1 second.
So, if I hover over #download
the fadeIn
should start after a 1 second delay. If I mouse out meanwhile the fadeIn
shouldn't start. Get me?
我真的不知道该怎么做,有什么想法吗?
I don't really know how to do that, any ideas?
需要使用setTimeout()
在这种情况下是因为 .delay()
有效(并且您无法取消它).
You need to use setTimeout()
in this case because of how .delay()
works (and your inability to cancel it).
$('.file a').live('mouseenter', function() {
$.data(this, 'timer', setTimeout(function() {
$('#download').stop(true, true).fadeIn('fast');
}, 1000));
}).live('mouseleave', function() {
clearTimeout($.data(this, 'timer'));
$('#download').stop(true, true).fadeOut('fast');
});
你可以在这里试试.
如果您使用 .delay()
它将使元素的下一个动画,无论您是否之前清除了该队列.所以你需要一个你可以取消的超时,上面通过手动调用 setTimeout()
并使用 $ 存储结果.data()
以便稍后通过 清除它clearTimeout()
.
If you use .delay()
it'll dequeue the next animation for the element, regardless of if you cleared that queue earlier. So you need a timeout that you can cancel, which the above does by manually calling setTimeout()
and storing the result with $.data()
so you can clear it later, via clearTimeout()
.
这篇关于延迟()或停止()超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!