I am writing a function to check if any of my section reaches the top of window then add a class. Not sure what I am missing any help would be really appreciated.
<body>
<section class="row"></section>
<section class="row"></section>
<section class="row"></section>
<section class="row"></section>
</body>
let _handleSectionAnimation = function() {
let sections = document.querySelectorAll('.row');
let currentScroll = window.pageYOffset || document.documentElement.scrollTop;
Array.prototype.forEach.call(sections, function(el, i) {
console.log("element scroll top = " + el.scrollTop);
let offsetElement = el.offsetHeight;
if(currentScroll > offsetElement) {
el.classList.add('animate');
}
});
}