Run function after delay

I have a global jQuery function, but when the page loads, I want to execute it after a delay of 1000. Is there something wrong with my syntax? I know that a delay always goes before a function. He does not respond.

Global function:

function showpanel() { $(".navigation").hide(); $(".page").children(".panel").fadeIn(1000); ;} 

Performing function:

 parallax.about.onload=function(){ $('#about').delay(3000).showpanel(); }; 
+55
jquery
Jun 02 2018-12-12T00:
source share
4 answers
 $(document).ready(function() { // place this within dom ready function function showpanel() { $(".navigation").hide(); $(".page").children(".panel").fadeIn(1000); } // use setTimeout() to execute setTimeout(showpanel, 1000) }); 

See here for more details.

+112
Jun 02 2018-12-12T00:
source share

I searched and found a solution in the following URL better .

http://www.tutorialrepublic.com/faq/call-a-function-after-some-time-in-jquery.php

Worth a try.

It adds your given function to the function queue that will be executed on the matching element, which is currently this one .

  $(this).delay(1000).queue(function() { // your Code | Function here $(this).dequeue(); }); 

and then execute the following function in the queue for the associated item (s), which is currently this again.

+29
Jan 05 '16 at 14:58
source share

You can add a timeout function in jQuery (Show warning after 3 seconds):

 $(document).ready(function($) { setTimeout(function() { alert("Hello"); }, 3000); }); 
+10
Dec 23 '16 at 10:55
source share

This answer is just useful for understanding how you can delay with the jQuery delay function.

Imagine that you have a warning and want to set the warning text, then show the warning and hide it after a few seconds.

Here is a simple solution:

 $(".alert-element").html("I'm the alert text").fadeIn(500).delay(5000).fadeOut(1000); 



It's simple:

  • .html() will change the text .alert-element
  • .fadeIn(500) will fade after 500 milliseconds
  • The jQuery delay(5000) function will make a 5000 millisecond delay before calling the next function.
  • .fadeOut(1000) at the end of the instruction .alert-element will disappear
+1
Jul 31 '16 at 12:55
source share



All Articles