Last active
August 29, 2015 14:21
-
-
Save tawadeparmeshwar/761604ec2f545d57399c to your computer and use it in GitHub Desktop.
It can be used for lazy load or infinite page load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* $(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