Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  11] [ 1]  / answers: 1 / hits: 35364  / 11 Years ago, mon, december 23, 2013, 12:00:00

This question was already asked here a long time ago:



Detect jquery event trigger by user or call by code



But it has never been answered conclusively (or maybe I'm simply not able to search properly).



Is it possible to detect whether a scroll event has been triggered by the user or by the jQuery animate function?



I am trying to prevent the scroll event to trigger itself while doing something like this:



$(document).scroll(function(){
$(html).stop(true);
var number = 400; //some other stuff is happening here
clearTimeout(tout);
tout = setTimeout(function(){
if(top == $(document).scrollTop()){
$(html).animate({
scrollTop: (number),
easing: easeInQuad,
duration: 110
});
}
},120);
});


This code seems to be suitable:



$('#scroller').scroll(function(e) {
if (e.originalEvent) {
console.log('scroll happen manual scroll');
} else {
console.log('scroll happen by call');
}
});


But the originalEvent object isn't able to detect the animate trigger properly.



Is there any other way to do this?


More From » jquery

 Answers
15

Maybe :animated selector will help you:



$('#scroller').scroll(function(e) {
if ($(this).is(':animated')) {
console.log('scroll happen by animate');
} else if (e.originalEvent) {
// scroll happen manual scroll
console.log('scroll happen manual scroll');
} else {
// scroll happen by call
console.log('scroll happen by call');
}
});


Demo


[#73588] Saturday, December 21, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aleighabayleef

Total Points: 511
Total Questions: 99
Total Answers: 99

Location: Aruba
Member since Fri, Jun 24, 2022
2 Years ago
aleighabayleef questions
Fri, Jun 5, 20, 00:00, 4 Years ago
Thu, Jun 4, 20, 00:00, 4 Years ago
Sat, Sep 21, 19, 00:00, 5 Years ago
Thu, Jul 18, 19, 00:00, 5 Years ago
;