Last active
December 3, 2019 18:26
-
-
Save davydka/41ca8c9f770d4ffa3dfb86b7f7eb0276 to your computer and use it in GitHub Desktop.
scrollMania, mobile safari viewport scroll shenanigans
This file contains hidden or 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
const scrollMania = () => { | |
const currentScroll = window.pageYOffset || document.documentElement.scrollTop | |
// a 100vh element minus the actual height of the window(aka viewport) | |
const testThreshold = heightRef.current.offsetHeight - window.innerHeight | |
const end = () => { | |
if(currentScroll !== scrollDelta) { | |
setScrollDelta(currentScroll) | |
} | |
return true | |
} | |
/****************************/ | |
if(window.innerHeight !== canvasElement.current.offsetHeight) { | |
setM('') | |
// down? near top? | |
if(currentScroll > scrollDelta && currentScroll > 0 && currentScroll < testThreshold) { | |
setTest(false) | |
} else { | |
setTest(true) | |
} | |
return end() | |
} | |
// up | |
if(currentScroll < scrollDelta && window.innerHeight === canvasElement.current.offsetHeight){ | |
setM('up - not enough') | |
setTest(false) | |
return end() | |
} | |
// up | |
if(currentScroll < scrollDelta && window.innerHeight !== canvasElement.current.offsetHeight){ | |
setM('up') | |
setTest(true) | |
return end() | |
} | |
// down | |
if(currentScroll > scrollDelta) { // scrolling down | |
setM('down') | |
setTest(false) | |
return end() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment