Skip to content

Instantly share code, notes, and snippets.

@vinaydotblog
Forked from tawadeparmeshwar/appear.js
Last active August 29, 2015 14:21
Show Gist options
  • Save vinaydotblog/5e8b5ac5e3e7668a3c47 to your computer and use it in GitHub Desktop.
Save vinaydotblog/5e8b5ac5e3e7668a3c47 to your computer and use it in GitHub Desktop.
/*
* $(elems).appear(function(elem){
* console.log("Reached elment", elem);
* });
*/
$.fn.appear = function(cb) {
var w_height = $(window).height();
this.each(function(){
var self = this;
var reached = false;
$(window).on('scroll', function(){
if(!reached) {
var body = $('body').scrollTop();
var more_pos = $(this).offset().top;
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