Skip to content

Instantly share code, notes, and snippets.

@tawadeparmeshwar
Last active August 29, 2015 14:21
Show Gist options
  • Save tawadeparmeshwar/761604ec2f545d57399c to your computer and use it in GitHub Desktop.
Save tawadeparmeshwar/761604ec2f545d57399c to your computer and use it in GitHub Desktop.
It can be used for lazy load or infinite page load
/*
* $(elems).appear(function(elem){
* console.log("Reached elment", elem);
* });
*/
$.fn.appear = function(cb) {
var more_pos = $(this).offset().top;
var w_height = $(window).height();
this.each(function(){
var self = this;
var reached = false;
$(window).on('scroll', function(){
if(!reached) {
var body = $('body').scrollTop();
if( more_pos <= body + w_height ) {
reached = true;
cb(self);
}
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment