jquery - Distinguishing between the user scrolling and programmatically scrolling using Javascript -
i'm creating scrolling effect using jquery , i'm wondering if it's possible distinguish between user scrolling vs. programmatically scrolling.
i have this:
$('#element').on('scroll',function(e){ $('#element').stop(true); // stop previous scrolling animation $('#element').animate({ // start new scrolling animation (maybe different speed, different direction, etc) scrolltop:... }); });
however, event triggered during every step of animation. how can tell if event triggered user or animation?
use variable determine when scrolling programmatically
example:
var programscrolling = false; $('#element').on('scroll',function(e){ if (programscrolling) { return; } $('#element').stop(true); // stop scrolling animation programscrolling = true; $('#element').animate({ scrolltop:... }); programscrolling = false; });
not sure if want, concept should work.
Comments
Post a Comment