Created
December 14, 2019 22:34
-
-
Save fireflysemantics/e8b3414e6ab20eff78c7ad7ebe77e6d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param scrollable The element being scrolled | |
* @param debounceMS The number of milliseconds to debounce scroll events | |
* @param sp The function returning the scroll position coordinates. | |
* @return A boolean valued observable indicating whether the element is scrolling up or down | |
*/ | |
export function scrollingUp( | |
scrollable: any, | |
debounceMS: number, | |
sp: scrollPosition): Observable<boolean> { | |
return fromEvent(scrollable, 'scroll').pipe( | |
debounceTime(debounceMS), | |
distinctUntilChanged(), | |
map(v => sp()), | |
pairwise(), | |
switchMap(p => { | |
const y1 = p[0][1] | |
const y2 = p[1][1] | |
return y1 - y2 > 0 ? of(false) : of(true) | |
})) | |
} | |
export type scrollPosition = ()=>[number, number] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment