Created
December 20, 2013 21:30
-
-
Save rquigley/8061863 to your computer and use it in GitHub Desktop.
Disable hover on scroll
This file contains hidden or 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
/** | |
* 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