Skip to content

Instantly share code, notes, and snippets.

@laocoi
Created April 8, 2018 14:56
Show Gist options
  • Save laocoi/fc3d7f8beff66fb00f58c2b8f5e1adff to your computer and use it in GitHub Desktop.
Save laocoi/fc3d7f8beff66fb00f58c2b8f5e1adff to your computer and use it in GitHub Desktop.
$(allInView);
$(window).scroll(allInView);
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
var inited = false;
function allInView() {
if (inited) {
return
}
if (isScrolledIntoView($(".postads"))){
alert('hù');
inited = true;
init();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment