Created
February 7, 2017 04:06
-
-
Save alextanhongpin/1243d1371618e3b216ab4cf9681ec8fa to your computer and use it in GitHub Desktop.
scroll-sixty-fps.js
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
/* | |
* 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