简体   繁体   中英

How to delay an event in jQuery?

In jQuery can you do something after you press a button and the timer starts to go from 3 seconds down to 0?

Like you have a button. You press it. 3 Seconds go by and bam.. an event fires.

The delay() function ( doc ) :

Description: Set a timer to delay execution of subsequent items in the queue.

For your example:

$("button").click(function() {
    $("[element]").delay(3000).fadeOut("slow");
});

您可以使用.delay()引用

You can use the .delay() -function.

They have a nice example in the documentation about this, which fits exactly to your question.

$("button").click(function() {
  $("yourelement").delay(3000).fadeIn(400);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM