Created
December 2, 2013 15:38
-
-
Save LouisWhit/7751304 to your computer and use it in GitHub Desktop.
Disable pointer events to improve scrolling performance on websites that have many hover effects.
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
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); |
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
.disable-hover, | |
.disable-hover * { | |
pointer-events: none !important; | |
} |
Hello @joebentaylor1995 ,
I am sure it would. I generally debounce several things. I would just place this in the debounce function for the site.
I have not looked into it recently. I would think you could most likely find a better way of doing this than I did 8 + years ago. I wouldn't trust this as a source of truth. I haven't updated these Gists in a very very long time. They are generally geared to my specific use cases in a few custom CMS systems I worked on during this time frame.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would this not benefit from a debounce?