我得到“各”:遗漏的类型错误:在animateIfInview 在atonscroll遗漏的类型错误:无法读取属性未定义
和继承人无法读取属性未定义 “每个”代码:
<script>
function animateIfInView() {
$.each($("content-img"), function(key, value) {
if (isElementInViewport($(value))) {
$(value).addClass("content-img-in-view");
} else {
// (Optional) Fade out when out of view
$(value).removeClass("content-img-in-view");
}
});
}
// http://stackoverflow.com/a/7557433/5628
function isElementInViewport(el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
(window.innerHeight ||
document.documentElement.clientHeight) /*or $(window).height() */ &&
rect.right <=
(window.innerWidth ||
document.documentElement.clientWidth) /*or $(window).width() */
);
}
</script>
我该如何解决这个错误?我在代码中缺少什么?谢谢你们提前
此:'$( “内容IMG”)'是不正确的选择。这是一个ID还是一个类? – Twisty
我也建议使用'$(“。content-img”)。each();' – Twisty
它为一个类,因此该页上的每个图像在滚动事物上都会淡入淡出 – nellement