Jquery delay on fadeout

user272899 picture user272899 · Mar 24, 2010 · Viewed 44.7k times · Source

I have this code that changes the opacity of the div on hover.

$("#navigationcontainer").fadeTo("slow",0.6); 

$("#navigationcontainer").hover(function(){ $("#navigationcontainer").fadeTo("slow",
    1.0); // This sets the opacity to 100% on hover },function(){ 

$("#navigationcontainer").fadeTo("slow",
    0.6); // This sets the opacity back to 60% on mouseout });

I want to have a delay before setting the div back to 0.6 opacity how would i do this

Answer

peirix picture peirix · Mar 24, 2010

With jQuery 1.4, you have a method called delay, which takes an integer representing ms you want to delay

$("#navigationcontainer").delay(500).fadeTo("slow", 0.6);

Half a second delay