0

I have a few images with a div and header on it that when mouse entering it slides up and leaving vise versa. It works, however the slidedown doesn’t happen right away. So, if I hover the mouse over it a few times quickly (lets say 10 times) it will slide up and down for like 30 seconds. I know there is something wrong in my code. Any ideas?

$(document).ready(function(){ $('.indexgall').on('mouseenter',function(){ $(this).addClass('hoverimg'); $(this).children().animate({ top:150 },600,function(){ }); }); $('li').on('mouseleave',function(){ $(this).removeClass('hoverimg'); $(this).children().animate({ top:250, },600,function(){ }); $(this).stop().animate({}); }); }); // END DOCMENT READY 

.hoverimg { box-shadow: .2% .2% .2% gray; /*2px 2px 2px gray */ opacity: 0.8; } 

JsFiddle

5
  • Please post your HTML, and a jsfiddle would be helpful :) Commented Dec 11, 2014 at 20:31
  • You have to use .stop() for animated children. BTW, $(this).stop().animate({}); doesn't make much sense Commented Dec 11, 2014 at 20:34
  • JSfiddle posted :) and i took out the (stop) but same thing. Commented Dec 11, 2014 at 20:38
  • Why not just use the :hover psuedo-class in CSS? Commented Dec 11, 2014 at 20:40
  • You folks should be using stack snippets for this. Commented Dec 11, 2014 at 22:34

1 Answer 1

1

Animations queue up when called on the same element. You should call .stop() before you call .animate().

$(this).children().stop().animate({ 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.