0

I need to differentiate between a scroll the code does and a scroll the user does. This is what I'm trying to do:

window.auto_scrolling = true;
$('html, body').animate({ 
   scrollTop: $(document).height()-$(window).height()},
   {duration: 500, easing: 'swing', done: function(e) {
        window.auto_scrolling = false;
    }}
);

However, despite being set to false in the done function, window.auto_scrolling is false in the last event caught by the $(window).scroll event handler.

Here's a JS fiddle showing my problem: http://jsfiddle.net/uLq9X/

Joren
  • 9,273
  • 18
  • 61
  • 103
  • [This](http://stackoverflow.com/questions/1659204/call-scroll-only-when-user-scrolls-not-when-animate/1659231#1659231) may also come to help – Itay Sep 14 '13 at 07:28
  • The first one isn't relevant at all. The second one looks relevant, but is very out-dated and does not work anymore. – Joren Sep 14 '13 at 09:36
  • The second one can be suitable for you. Just create a boolean indicating whether a scrolling animation is being executed or not. Like you already understand, there's probably no natural solution for this requirement. – Itay Sep 14 '13 at 09:38
  • That's what I'm doing, but the done event fires before the last scroll event. The method suggested in the link doesn't work (it never calls the function) – Joren Sep 14 '13 at 22:20
  • If you make a simple fiddle I'll try and help you further – Itay Sep 15 '13 at 03:33

0 Answers0