Skip to content

Instantly share code, notes, and snippets.

@m4tlch
Forked from grayghostvisuals/disable-scroll.js
Created December 17, 2018 15:40
Show Gist options
  • Save m4tlch/edae02dd63f6b221c0bc7f80cb387218 to your computer and use it in GitHub Desktop.
Save m4tlch/edae02dd63f6b221c0bc7f80cb387218 to your computer and use it in GitHub Desktop.
Disable hover on scroll to improve performance and avoid costly paints.
// Disable Hover on Scroll Class
// Add these helpers to your utlity.css
// http://www.thecssninja.com/javascript/pointer-events-60fps
.disable-hover,
.disable-hover * {
pointer-events: none !important;
}
// ----------------------------------------------------------------------
// =Disable Hover on Scroll
// http://www.thecssninja.com/javascript/pointer-events-60fps
// ----------------------------------------------------------------------
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment