Skip to content

Instantly share code, notes, and snippets.

@gcpantazis
Last active December 24, 2015 17:09
Show Gist options
  • Save gcpantazis/6833091 to your computer and use it in GitHub Desktop.
Save gcpantazis/6833091 to your computer and use it in GitHub Desktop.
Element scrolled into view, with a 100 pixel threshold.
var checkActive = function(el) {
var self = this,
elRect = el.getBoundingClientRect(),
winRect = document.documentElement.getBoundingClientRect(),
isNearBottom = winRect.bottom - elRect.bottom < 100 && $(document).height() - ($(window).scrollTop() + $(window).height()) < 100;
if (elRect.top < 100 && elRect.top > 0 || isNearBottom) {
// Element is scrolled into view.
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment