Detecting jquery event trigger by user or calling by code

I have a window.onscroll event

 $(window).scroll(function(e){ //My Stuff }); 

but in my code I call an animated scroll to some line where

 $('html, body').stop().animate({ scrollTop:555 }, 1000); 

since I found that the page was scrolling by the user or calling my code. My current solution is flagged before calling animate in my code, then clear it, but this is not a smart solution. I also read about the detection of e.which or e.originalEvent , but it does not work. I think your expert has a good solution here.

+10
javascript jquery
Jun 15 '12 at 10:52
source share
2 answers
 $('#scroller').scroll(function(e) { if (e.originalEvent) { // scroll happen manual scroll console.log('scroll happen manual scroll'); } else { // scroll happen by call console.log('scroll happen by call'); } }); $('#scroller').scroll(); // just a initial call 

When scrolling by a call, e.originalEvent will be undefined , but when scrolling manually, it will give a scroll object.

Demo

+18
Jun 15 '12 at 11:24
source share

ive re-asked this question and got 2 helpful answers.
I will link this question here for others who find this topic.

Detect if scroll event fires manually in jQuery

+3
Dec 23 '13 at 7:33
source share



All Articles