I am getting : Uncaught TypeError: Cannot read property 'each' of undefined at animateIfInview at atonscroll
and heres the code :
<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>
How can I fix this error? what am I missing in code? Thanks guys in advance