开发者

jQuery change CSS after a certain amount of time

开发者 https://www.devze.com 2023-01-29 18:08 出处:网络
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 secon开发者_运维问答ds, I would like the z-index to be changed to 2.

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 secon开发者_运维问答ds, 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.


Use a setTimeout like this

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


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

setTimeout("javascript statement",milliseconds);

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

0

精彩评论

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