why my delay function is not working in Jquery when i use it to delay $(document).ready ? help me out

StackOverflow https://stackoverflow.com/questions/18547163

  •  26-06-2022
  •  | 
  •  

Question

I want that my div to shows up just after 5 seconds document is ready so I used

$(document).ready(function(){
    delay(function(){
        $('#up').slideDown("slow");
    },4000);
});

but it's not working, the document loads when I don't use delay function. It works using :

$(document).ready(function(){
    setTimeout(function(){
        $('.hidden').slideDown("slow");
    },4000);
});

And I don't want to use set-timeout function so how can I do this with delay function.

Était-ce utile?

La solution

There is no method called delay in javascript, you need to use setTimeout as you shown above.

$(document).ready(function () {
    setTimeout(function () {
        $('.hidden').slideDown("slow");
    }, 4000);
});

There is a .delay() method provided by jQuery, it is for delays items added in the queue

$('.hidden').delay(4000).slideDown("slow");

Demo: Fiddle

still if you don't want to use setTimeout then create an alias for it like (Just for fun)

var delay = setTimeout;
delay(function () {
    $('.hidden').slideDown("slow");
}, 4000);

Autres conseils

you can use this code

.slideDown()

$('#up').slideDown(4000); //time in ms

DEMO

Try this

$(document).ready(function () {
   $('.hidden').delay(4000).slideDown("slow");
});

Hope this helps,Thank you

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top