Jquery- Hide/Show a div after a duration on page load

我与影子孤独终老i 提交于 2019-12-13 02:26:18

问题


I have a div which will display after some time .i.e on page load it will be invisible and after some duration it will be visible.

I tried this, but its not working for me.

setTimeout($(".startab").show(),4000);
$(".startab").delay(4000).show();

JS FIDDLE DEMO


回答1:


Need to use a closure

setTimeout(function () {
    $(".startab").show()
}, 4000);

setTimeout takes a function as the first parameter and you were passing it an object

Fiddle




回答2:


setTimeout() accepts a callback and a duration and should be called like this:

setTimeout(function() {$(".startab").show()},4000);


来源:https://stackoverflow.com/questions/18634783/jquery-hide-show-a-div-after-a-duration-on-page-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!