I'm using animate()
to animate the DIV tag to the left when the pointer is over the DIV. And when the pointer leaves the DIV tag it animates back to it's original position. The problem here is that the animation moves the DIV tag 50 pixels to the left on mouse over and 50 pixels to the right on mouse leave.
This makes the DIV to move 50 pixels to the right even if the animation is not completed.
$('body').on('mouseenter', '.image-photo-previous', function() {
$(this).animate({marginLeft: '-=50px'}, 300, 'swing');
});
$('body').on('mouseleave', '.image-photo-previous', function() {
$(this).animate({marginLeft: '+=50px'}, {queue: false}, 300, 'swing');
});
http://jsfiddle.net/edgren/CubZy/
How can I make the DIV tag to animate back to its original position even if the animation is not complete on mouse leave?