jquery - Delay hover animation -


this question has answer here:

my code is:

$(document).ready(function() {     $('.holder').hover(function() {         $(this).find('.heading').slideup();      },function() {         $(this).find('.heading').slidedown();     }); }); 

now want implement settimeout function. problem $(this)

just store $(this) in variable , use variable within anonymous function:

$(document).ready(function() {     $('.holder').hover(function() {         var $self = $(this);         settimeout(function(){           $self.find('.heading').slideup();          }, 500);     },function() {         $(this).find('.heading').slidedown();     }); }); 

edit in response comments:

$(document).ready(function() {     var timer;     $('.holder').hover(function() {         var $self = $(this);         timer = settimeout(function(){           timer = false;           $self.find('.heading').slideup();          }, 2000);     },function() {         if(timer){             cleartimeout(timer);             timer = false;         }else{             $(this).find('.heading').slidedown();         }     }); }); 

Comments

Popular posts from this blog

ruby on rails - Is it the correct way to implement belongs_to relation with factory girl? -

geolocation - Windows Phone 8 - Keeping background location tracking active beyond four hours -

Uncaught TypeError: Cannot read property 'parentNode' of null javascript -