Skip to content

Instantly share code, notes, and snippets.

@davydka
Last active December 3, 2019 18:26
Show Gist options
  • Save davydka/41ca8c9f770d4ffa3dfb86b7f7eb0276 to your computer and use it in GitHub Desktop.
Save davydka/41ca8c9f770d4ffa3dfb86b7f7eb0276 to your computer and use it in GitHub Desktop.
scrollMania, mobile safari viewport scroll shenanigans
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