:hover
when scrolling - it allows you to keep the site responsive, but it has one drawback - you have to rely on one general class, and this is bad. .hover .element:hover { box-shadow: 1px 1px 1px #000; }
.hover
class from the body
tag, thereby turning off all your selectors with :hover
. After the end of the event, the class returns, and the effects :hover
back in business. .disable-hover { pointer-events: none; }
body
at the beginning of the scroll, and that's it - the mouse “flies”! 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);
body
, and if not, add it. Then we simply add a new timer, which, half a second after the end of the scroll, will reset our class. Everything!pointer-events: auto
style on the page, they will grind the global class and will still slow down. We don't want that, right? .disable-hover, .disable-hover * { pointer-events: none !important; }
*
with the flag !important
we will teach our elements to behave well.hover
, and without. The result is impressive!Source: https://habr.com/ru/post/204238/
All Articles