There are two functions

var widget = $('popup'); function show() { widget.show(); }; function hide() { widget.show().delay(delay).fadeOut(); }; 

The problem is that if show() is called before hide() finished executing, then the displayed element will disappear anyway.

Is it possible to interrupt previous actions for a widget when calling show() ?

  • one
    method .stop() - lexxl

1 answer 1

@lexxl, slightly correcting the comment, I achieved the desired. I used stop() myself, but it didn’t work without arguments.

 var widget = $('#popup').hide(); $('#show').click(function(e) { widget.stop(true).show(); }); $('#hide').click(function(e) { widget.show().delay(7000).fadeOut(); }); 
 #popup { border: 1px solid; margin: 10px; padding: 10px; width: 200px; text-align: center; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="popup">Контент внутри</div> <input type="button" id="show" value=Показать> <input type="button" id="hide" value="Скрыть">