jQuery在一定时间后更改CSS [英] jQuery change CSS after a certain amount of time
本文介绍了jQuery在一定时间后更改CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个导航,当其中一个导航项目被点击,将使用jQuery将其z-index更改为0.然后,2秒后,我想z-index更改为2。 / p>
我尝试使用delay(),但显然在更改CSS时不起作用。
解决方案
使用像这样的setTimeout
$(elem).css('z-index' 0');
setTimeout(function(){$(elem).css('z-index','2');},2000)
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.
解决方案Use a setTimeout like this
$(elem).css('z-index','0'); setTimeout(function(){ $(elem).css('z-index','2'); },2000)
这篇关于jQuery在一定时间后更改CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文