Skip to content

Instantly share code, notes, and snippets.

@rquigley
Created December 20, 2013 21:30
Show Gist options
  • Save rquigley/8061863 to your computer and use it in GitHub Desktop.
Save rquigley/8061863 to your computer and use it in GitHub Desktop.
Disable hover on scroll
/**
* Scrolling can become janky when elements are rolled over. This
* adds a class to the body that disables all hover-states when
* scrolling is occurring.
*/
disableHoverOnScroll: function() {
var timerInt;
var ticking;
var $body = $('body');
$(window).on('scroll', function() {
if (!ticking) {
rAF(_scrollHandler);
}
ticking = true;
});
function _scrollHandler() {
clearTimeout(timerInt);
if(!$body.hasClass('disable-hover')) {
$body.addClass('disable-hover');
}
timerInt = setTimeout(function(){
$body.removeClass('disable-hover');
},500);
ticking = false;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment