开发者

In Javascript/Jquery, how do I display a div for 5 seconds, and then have it fade out?

For example, when someone clicks on a bu开发者_JAVA技巧tton.


You're looking for the delay function:

$(something).delay(5000).fadeOut();    //5,000 milliseconds

In general, you can call setTimeout:

setTimeout(function() {
    //Do things...
}, 5000);


Use the delay function available since 1.4

From the docs: http://api.jquery.com/delay/

$('#foo').fadeIn(400).delay(5000).fadeOut(400);


In 1.4 you can use the .delay() function. Here's the documentation for that:

jQuery Docs

Alternately you could look into the native javascript setTimeOut() function.


If you're using the JQuery 1.4+, you could try

$('#myDiv').fadeIn('medium').delay(5000).fadeOut('medium');

You can remove the fadeIn if the div is visible straight away.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜