-
-
Save vinaydotblog/5e8b5ac5e3e7668a3c47 to your computer and use it in GitHub Desktop.
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 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