vinnizworld
5/25/2015 - 10:44 AM

appear.js

/*
 *  $(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);
          }

        }
      });
    });
  }