Had the same problem and after reading the last answer by amurra this is what I did...
Declared a global variable by attaching it to the 'window' object. This will act as a flag and decide whether to keep calling the 'slide_it()' function or to stop it (return)
window.slide_it = true;
$(element).on({
mouseenter:
function() {
window.slide_it = true;
slide_it();
}
mouseleave:
function() {
window.slide_it = false;
}
});
function slide_it () {
if( !window.slide_it )
return false;
$(element).stop().animate(
{
'left':'-=5px'
},
100,
function() { slide_it() }
);
}
Once you enter the mouse over the $(element) the slide_it() function will iterate itself. And it will stop only if window.slide_it is set to false. So you just set window.slide_it to false when "mouseleave"s
Hope it helps someone else having the issue!