Created
December 8, 2013 17:22
-
-
Save mateuszkocz/7860484 to your computer and use it in GitHub Desktop.
Avoid paints on scroll. Source: http://www.thecssninja.com/javascript/pointer-events-60fps . Instead of document.body you might want to use document.documentElement if you're using html adn body as a free div.
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
CSS | |
.disable-hover { | |
pointer-events: none; | |
} | |
JS | |
var body = document.body, | |
timer; | |
window.addEventListener('scroll', function() { | |
clearTimeout(timer); | |
if(!body.classList.contains('disable-hover')) { | |
body.classList.add('disable-hover') | |
} | |
timer = setTimeout(function(){ | |
body.classList.remove('disable-hover') | |
},500); | |
}, false); | |
OR | |
CSS | |
.scroll-cover { | |
top: 0; | |
left: 0; | |
bottom: 0; | |
right: 0; | |
position: fixed; | |
pointer-events: auto !important; | |
z-index: 10000; | |
} | |
JS | |
var body = document.body, | |
cover = document.createElement('div'); | |
cover.setAttribute('class','scroll-cover'); | |
window.addEventListener('scroll', function() { | |
clearTimeout(timer); | |
body.appendChild(cover); | |
timer = setTimeout(function(){ | |
body.removeChild(cover); | |
},500); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment