circey
circey

Reputation: 2042

mouseleave, clearing interval and stopping script

I've got this bit of code:

slider.controls.next.bind('mouseenter', function() {
    setInterval(clickNextBind, 300);
});

working with bxslider so that if the user hovers over the "next" button, the slideshow scrolls automatically. But I need it to stop when the user moves away from the "next" button.

I tried this:

slider.controls.next.bind('mouseleave', function() {
    clearInterval();
});

But it doesn't stop the scrolling. How should I be doing this?

MTIA.

Upvotes: 0

Views: 91

Answers (1)

Matt Zeunert
Matt Zeunert

Reputation: 16561

You need to pass a specific interval id to clearInterval:

var interval = 0;
slider.controls.next.bind('mouseenter', function() {
    interval = setInterval(clickNextBind, 300);
});

slider.controls.next.bind('mouseleave', function() {
    clearInterval(interval);
});

Upvotes: 1

Related Questions