3

I have the following code here:

<script>
$(document).ready(function() {

    $('.scrolls').stop().animate({
        scrollLeft : 4000
    },100000, 'linear')
})
</script>

I'd like to be able to stop the animation as soon as the user interacts with the scrollbar within that div. I'm a jquery newb so if anyone could help me out, would be MUCH appreciated!

Here's the fiddle.

  • http://stackoverflow.com/questions/8858994/let-user-scrolling-stop-jquery-animation-of-scrolltop – DaniP Jan 08 '14 at 16:15
  • That answer works on the jsfiddle, but doesn't work on my website. I'm using mamp right now, running wordpress, and first, it doesn't seem to recognize this part var $viewport = $('.scrolls'); and if I change all the $viewport to $('.scrolls'), the animation will start, but won't stop. So it's not recognizing the .bind portion. I'm a jquery newb, so I don't know WHY it's not doing it, but it isn't. :/ – user3158649 Jan 08 '14 at 16:46

1 Answers1

0

I just tried to stop the animation on click and it worked I think all you need to do is to decide what events you want to listen for:

I used:

    $(".scrolls").on("click",function(){
        $(this).stop(true,false);
});

jsfiddle

VicJ
  • 121
  • 6