JQuery changes CSS after a certain amount of time

I have a navigation that when one of them inherits the elements, it will use jQuery to change the 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 this does not work when changing CSS.

+3
source share
2 answers

Use setTimeout like this

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

In javascript you can use setTimeout or setInterval to accomplish this

setTimeout("javascript statement",milliseconds);

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

+2
source

Source: https://habr.com/ru/post/1670189/


All Articles