Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery delay on fadeout

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

like image 374
user272899 Avatar asked Mar 24 '10 15:03

user272899


2 Answers

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

like image 61
peirix Avatar answered Nov 08 '22 10:11

peirix


use set timeout with a callback to the functionality you want and a delay that you want.

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

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


var delay = 1000;
setTimeout(function() 
    { 
        $("#navigationcontainer").fadeTo("slow",
            0.6); // This sets the opacity back to 60% on mouseout });

    },
    delay
) 
like image 30
MedicineMan Avatar answered Nov 08 '22 10:11

MedicineMan