Last active
August 5, 2017 17:04
-
-
Save tzkmx/1bb5c35b8dc6b698b51141dc45c8aea5 to your computer and use it in GitHub Desktop.
Waypoints to detect element just coming to viewport
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
(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment