I'm looking to implement scrolling functionality like the Google Inbox landing page has:
Notably, no matter how fast or how many times you scroll the wheel, it will count as "one" and go to the next step. This seems easier said than done since there's no way to cancel "scroll" event. There is a way to cancel DOMMouseScroll
& mousewheel
events however doing so is tricky:
The problem is the way cancelling these events works is like below using return preventFn(ev)
:
var preventFn = function (ev) {
ev.returnValue = false;
return false;
};
However doing so causes scrollTop()
action to break. But without it, the scroll event passes through and messes it up also.
I can do better with a rather buggy implementation using a timeout (see fiddle). It works alright but has major bug being everything permanently breaks if the user scrolls WHILE the scrollTop()
animation is happening.
How can I correct this so it's as awesome as Google did? (and preferably without a timeout. In the Google page, going from 3rd to 4th step ... I cannot even perceive any timeout, it seems to scroll immediately as my mousewheel starts moving. so it seems possible)