如何延迟警报?
我试图延迟警报,但无法让它工作,当 #foo 悬停在上方并且大小增加时,它总是弹出:
$('#foo').hover(function() {
$(this).animate({width :'400px'}, 'slow');
},
function() {
$(this).delay(2000).animate({width :'40px'}, 'slow');
alert('Im an alert message');
});
但我希望它仅在 #foo 减少回原始状态后才显示。 ..
I'm trying to delay an alert but can't get it to work, it always pops up when #foo is hovered over and is increasing in size:
$('#foo').hover(function() {
$(this).animate({width :'400px'}, 'slow');
},
function() {
$(this).delay(2000).animate({width :'40px'}, 'slow');
alert('Im an alert message');
});
but I want it to show only after #foo has decreased back to original state ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用回调怎么样?
How about Using a callback ??
您需要在回调中执行此操作。这是动画完成时将调用的函数:
请参阅
animate
API< /a>.You need to do this in a callback. This is a function that will be called when the animation is complete:
See the
animate
API.看起来您想在 animate 函数上使用回调?
http://api.jquery.com/animate/
it looks like you want to use a callback on the animate function?
http://api.jquery.com/animate/
使用setTimeout函数:http://www.w3schools.com/js/js_timing.asp
上面的代码应该延迟 3 秒。
Use the setTimeout function: http://www.w3schools.com/js/js_timing.asp
The above code should delay for 3 seconds.