Skip to content

Instantly share code, notes, and snippets.

@hugofabricio
Last active November 24, 2016 02:18
Show Gist options
  • Save hugofabricio/75b19b5ac272c92fe6e4ae09666afc1d to your computer and use it in GitHub Desktop.
Save hugofabricio/75b19b5ac272c92fe6e4ae09666afc1d to your computer and use it in GitHub Desktop.
(function ($) {
$.fn.scrolledIntoView = function(){
var elem = $(this),
docViewTop = $(window).scrollTop(),
docViewBottom = docViewTop + $(window).height(),
elemTop = $(elem).offset().top,
elemBottom = elemTop + $(elem).height();
return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) && (elemTop >= docViewTop));
};
}( jQuery ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment