简体   繁体   English

防止多次点击识别符

[英]Prevent multi delays on click of identificator

I have this code: 我有以下代码:

$(element).on('click', function() {
    $this.closest('div').before('<span id="message" style="display:none"></span>');
    $('#message').fadeIn().delay(5000).fadeOut();

Where as you see, on the click of the specified element, I'm going to fade in a span#message before the div, wait 5 seconds and then fade out the span. 如您所见,在单击指定元素的位置上,我将在div之前淡入span #message中,等待5秒钟,然后淡出该范围。

I tried adding stop() before the fadein but this helps only to prevent multi-animations on click, what I need is a way to prevent multi-delays on click, because an user, when try to click the specified element, will see the span fading every 5 seconds as the number of clicks on the specified element. 我尝试在fadein之前添加stop(),但这仅有助于防止单击时出现多动画,我需要一种防止单击时出现多延迟的方法,因为用户在尝试单击指定的元素时将看到每5秒钟一次跨度随着指定元素上的点击次数而逐渐减少。

Fiddle: https://jsfiddle.net/43z78dk6/ 小提琴: https : //jsfiddle.net/43z78dk6/

http://api.jquery.com/stop/ http://api.jquery.com/stop/

If you pass in true to the stop() , it will jump past any queued animations, and they will be ignored. 如果将true传递给stop() ,它将跳过所有排队的动画,并且它们将被忽略。

 var $element = $('button'); $element.closest('div').before('<span id="elementFade" style="display:none">You clicked him!</span>'); $element.on('click', function() { //pass in true to end all queued animations //you can click all you want $('#elementFade').stop(true).fadeIn().delay(5000).fadeOut(); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <button>You know you want to click me</button> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM