3

I have some code that listens to the scrolling of a page and it's responsible for two things, performing the necessary action (which works) when the "page" has changed but also animate the scrollTop to the nearest "page" but in doing so the scroll event is fired so it sequentially crawls through all the "pages" until it reaches the end of the document.

How can I stop animate scrollTop from firing the scroll event? Is it even possible?

"pages" because this is an iPad html page and each 1024x768 view is a "page"

Dave Mackintosh
  • 2,738
  • 2
  • 31
  • 40

1 Answers1

1

You can find a answer at this post : https://stackoverflow.com/a/1659231/237838

You could make write your own code to set the animation value, and set a flag indicating that the change comes from an animation.

For example: (Untested)

var scrollAnimating = false
jQuery.fx.step.scrollTop = function(E) {
    scrollAnimating = true;
    E.elem.scrollTop = E.now;
    scrollAnimating = false;
};

$('#gototop').click(function() {
    $('body').animate({scrollTop:0},3000);
    $(window).scroll(function () {
        if (!scrollAnimating)
            $('body').stop();
    });
    return false;
})
Community
  • 1
  • 1
Francois Borgies
  • 2,378
  • 31
  • 38
  • 3
    Thank you for editing in the attribution. However, now your posts are really just worthy of a comment, not an answer; you really need to include your own information in your answers - not just a copy and paste of someone else's code - even if you include attribution. – Andrew Barber Apr 23 '13 at 18:37
  • is this Tested, if so can you paste Demo URL ? – Raj Kumar Samala Aug 23 '16 at 11:48