Last active
April 11, 2017 02:42
-
-
Save sinrise/9ba66212b67c9970e19a884b390f834a to your computer and use it in GitHub Desktop.
Alternative to a persistent scroll event listener. This fires only when the user scrolls, then stops after 250ms.
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
var timeout = null; | |
$(window).scroll(function () { | |
if(!timeout) { | |
timeout = setTimeout(function() { | |
clearTimeout(timeout); | |
timeout = null; | |
if ($(window).scrollTop() >= $("#navTtigger").offset().top) { | |
$("nav").addClass("fixed"); | |
} else { $("nav").removeClass("fixed"); } | |
}, 250); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment