jquery - Delay hover animation -
this question has answer here:
- how pass 'this' settimeout callback 8 answers
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
Post a Comment