tzkmx
8/1/2017 - 7:49 PM

Waypoints to detect element just coming to viewport

Waypoints to detect element just coming to viewport

(function($, w){

	$(document).ready(function(){
		w.waypoints = Array();
		
		function printCoordinates(direction, waypoint) {
			return function(scrollDirection) {
				if(scrollDirection === direction) {
					var c = waypoint.element.getBoundingClientRect();
					console.log(i, d, 'top ' + c.top, 'bottom ' + c.bottom);
					waypoint.destroy();
				}
			}
		}
		
		$('.share-post-dev').each(function(i, el){
			var wpdown = new Waypoint({
				element: el,
				handler: printCoordinates("down", this),
				offset: function() {
					return Waypoint.viewportHeight() + 10;
				}
			});
            var wpup = new Waypoint({
                element: el,
                handler: printCoordinates("up", this),
                offset: function() {
                    return -(this.adapter.innerHeight() + 10);
                }
            });
			w.waypoints.push({up:wpup,down:wpdown});
			var c = el.getBoundingClientRect();

            console.log(i, 'top ' + c.top, 'bottom ' + c.bottom);
		});
		setTimeout(function(){
			Waypoint.refreshAll();
		}, 1000);
	});

})(jQuery, window);