jQuery change CSS after a certain amount of time

吃可爱长大的小学妹 提交于 2019-12-18 06:48:38

问题


I have a navigation that, when one of it's nav items is clicked, will use jQuery to change it's z-index to 0. Then, after 2 seconds, I would like the z-index to be changed to 2.

I tried using delay() but apparently that doesn't work when changing the CSS.


回答1:


Use a setTimeout like this

$(elem).css('z-index','0');
setTimeout(function(){ $(elem).css('z-index','2'); },2000)



回答2:


In javascript you can use either setTimeout or setInterval to accomplish that

setTimeout("javascript statement",milliseconds);

http://www.w3schools.com/js/js_timing.asp



来源:https://stackoverflow.com/questions/4411644/jquery-change-css-after-a-certain-amount-of-time

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