启动jQuery fadeOut()后,如何取消它? [英] How do you cancel a jQuery fadeOut() once it has started?
本文介绍了启动jQuery fadeOut()后,如何取消它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基本的div元素来表示我显示几秒钟的消息,然后使用淡出
I have a basic div element to represent a message that I show for a few seconds and then fade it out using
$('#message').fadeOut(5000);
如果用户将鼠标悬停在div上,我希望能够取消淡出.
I want to be able to cancel the fade out if the user hovers their mouse over the div.
一旦fadeOut方法开始使div褪色,如何取消淡出?
How can I cancel the fade out once the fadeOut method has started to fade the div?
如果鼠标在显示时进入div,则下面的我现有的代码可以工作,但是我需要允许用户在div开始消失后将鼠标悬停在div上.
My existing code, below, works if the mouse enters the div whilst it is being shown but I need to allow for if the user hovers over the div once it has started to fade.
$('#message').mouseenter(function() {
clearTimeout(this.timeout);
});
$('#message').mouseleave(function() {
this.timeout = setTimeout("$('#message').fadeOut(5000)", 3000);
});
$('#message').fadeIn(2000, function() {
this.timeout = setTimeout("$('#message').fadeOut(3000)", 3000);
});
推荐答案
查看停止功能
http://docs.jquery.com/Effects/stop#clearQueuegotoEnd
这篇关于启动jQuery fadeOut()后,如何取消它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文