Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created February 7, 2017 04:06
Show Gist options
  • Save alextanhongpin/1243d1371618e3b216ab4cf9681ec8fa to your computer and use it in GitHub Desktop.
Save alextanhongpin/1243d1371618e3b216ab4cf9681ec8fa to your computer and use it in GitHub Desktop.
scroll-sixty-fps.js
/*
* 60 FPS Scroll
*
* prevent accidental click on links
* prevent other touch-related events
* 60fps scroll
*
* Usage:
* import Scroll from './scroll'
* Scroll()
**/
export default function init () {
const body = document.body
const className = 'is-disabled'
const timeoutInterval = 500
let timeout = null
window.addEventListener('scroll', (evt) => {
const hasClassName = body.classList && body.classList.contains(className)
if (!hasClassName) {
body.classList.add(className)
}
if (timeout) {
window.clearTimemout(timeout)
}
timeout = window.setTimeout(() => {
body.classList.remove(className)
}, timeoutInterval)
}, false)
return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment