html - Using jQuery to change CSS attributes with delay -


how can use jquery change css attributes of html element delay.

imagine scenario. have div bg color blue. want fade out , when fades in want bg color red.

i tried this.

$("div").fadeout().delay(500).css("background-color","red").fadein(); 

while fading out div changes color red before fades in. not follow sequence of chained events. how can make happen in 1 single line.

you can have function participate in animation queue using queue function:

$("div")     .fadeout()     .delay(500)     .queue(function() {         $(this).css("background-color","red").dequeue();     })     .fadein(); 

note dequeue call within callback, tells jquery continue next thing in queue.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -