How can I configure a custom function after a delay?

How to set up custom circuit function after delay has been set

here is what i mean: http://jsbin.com/uluyim

$(function(){ $('.container').hide(); $('.container').delay(2000).fadeIn().$(document).callMe(); function callMe () { alert ("It works!"); } }); 

Thanks!

+6
source share
4 answers

Change line below

 $('.container').delay(2000).fadeIn().$(document).callMe(); 

to

 $('.container').delay(2000).fadeIn(callMe) 
+10
source

In your case, you can use arunes solution using callback from animation. However, if you need to add a delay between the animation and the callback that is running, you can do this too, as in:

 $('.container').fadeIn(function () { $(this).delay(2000).queue(function () { alert('Custom function executed two seconds after fadeIn()!'); $(this).dequeue(); }); }); 
+2
source

All jQuery animation methods have trailing callbacks that let you run the code after the animation.

 $('.container').hide().delay(2000).fadeIn(callMe) ;; 
+1
source
 $(function(){ $('.container').hide(); $('.container').delay(2000).fadeIn(callMe); }); function callMe () { alert ("It works!"); 
0
source

Source: https://habr.com/ru/post/909771/


All Articles