Jquery delay() function

前端 未结 2 1642
一个人的身影
一个人的身影 2020-12-29 05:29

I have some jquery and am trying to apply a delay to it but can\'t seem to get it to work.

The current jquery is as follows...

image.css({\"visibilit         


        
相关标签:
2条回答
  • 2020-12-29 06:06

    The delay() function only applies to actions queued on the element. Most commonly, but not always, these are actions created by the animate() method. In this case, use setTimeout to run some code after a specified interval.

    Try this:

    setTimeout(function() {
        image.css({"visibility" : "hidden"}).removeClass("image-background");
    }, 800);
    
    0 讨论(0)
  • 2020-12-29 06:14

    .delay() is not only for animations.

    It's for anything in a queue.

    image.delay(800)
         .queue(function( nxt ) {
             $(this).css({"visibility":"hidden"}).removeClass("image-background");
             nxt(); // continue the queue
         });
    

    For the down voter:

    HERE'S A DEMO

    0 讨论(0)
提交回复
热议问题