delay() or timeout with stop()?(延迟()或停止()超时?)
问题描述
$('.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()
.
这篇关于延迟()或停止()超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:延迟()或停止()超时?


- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01