Skip to content

Instantly share code, notes, and snippets.

@mateuszkocz
Created December 8, 2013 17:22
Show Gist options
  • Save mateuszkocz/7860484 to your computer and use it in GitHub Desktop.
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.
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