Skip to content

Instantly share code, notes, and snippets.

@halfempty
Last active May 24, 2017 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halfempty/aca5a5a78063713dddb742b6e8228048 to your computer and use it in GitHub Desktop.
Save halfempty/aca5a5a78063713dddb742b6e8228048 to your computer and use it in GitHub Desktop.
Notes for Will
// Checking visibility
jQuery.fn.isScrolledIntoView = function () {
var thisOffset = $(this).offset().top;
var windowHeight = $(window).height();
var heightToThis = thisOffset - windowHeight;
var scrollPosition = $(window).scrollTop();
if ( (scrollPosition >= heightToThis ) ) {
return true;
}
}
// Timer on scroll
$(window).scroll(function(){
// Resize actions are in handleScroll()
if (scrollTimer) {
clearTimeout(scrollTimer); // clear any previous pending timer
}
scrollTimer = setTimeout(handleScroll, 1); // set new timer
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment