I'm attempting to animate some text when they come into view. Things work fine but when I introduce pagepiling.js, my function for determining if my elements are in view returns false. Here is the function:
function elementInViewport(el) {
var top = el.offsetTop;
var left = el.offsetLeft;
var width = el.offsetWidth;
var height = el.offsetHeight;
while (el.offsetParent) {
el = el.offsetParent;
top += el.offsetTop;
left += el.offsetLeft;
}
return (
top < (window.pageYOffset + window.innerHeight) &&
left < (window.pageXOffset + window.innerWidth) &&
(top + height) > window.pageYOffset &&
(left + width) > window.pageXOffset
);
}
Any ideas on what could be wrong?
Please check how to use of the pagePiling.js callbacks for that such as
afterLoad
andonLeave
.You can also check the available example within the
examples
folder of the github repo.