当它们出现时,我正在尝试为一些文本设置动画。一切正常,但是当我引入 pagepiling.js 时,用于确定我的元素是否在视图中的函数返回 false。这是功能:
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
);
}
关于什么可能是错误的任何想法?