0

What I am trying to do obviously is target a specific "gridWrap" element (the one being hovered over) and remove a class after 500ms but it doesn't seem to work.

Here is what I have

$(".gridWrap").mouseleave(function(){
  setTimeout(function(){
    $(this).find('.gridOverlay').removeClass('active');
  }, 500);
  $(this).find('.viewSite').removeClass('bounceInDown').addClass('bounceOutUp');
});

This works just fine but i need to delay the "active" class removal:

$(".gridWrap").mouseleave(function(){
$(this).find('.gridOverlay').removeClass('active');
$(this).find('.viewSite').removeClass('bounceInDown').addClass('bounceOutUp');
});
agon024
  • 1,007
  • 1
  • 13
  • 37

2 Answers2

0

As mentioned before, the this context changes in timeout function. Try this one:

$(".gridWrap").mouseleave(function(){
  var self = $(this);
  setTimeout(function(){
    self.find('.gridOverlay').removeClass('active');
  }, 500);
  $(this).find('.viewSite').removeClass('bounceInDown').addClass('bounceOutUp');
});
papa zulu
  • 317
  • 5
  • 16
0

Create a variable for this before 'settimeout' it work well

N.J.honey
  • 44
  • 3