一旦它开始,你如何取消jQuery fadeOut()? [英] How do you cancel a jQuery fadeOut() once it has began?
本文介绍了一旦它开始,你如何取消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屋!
查看全文