JSFiddle - React, Tailwind, and code Playground
by adelura
JavaScript
var elements = [
$('.something'),
$('.something-else')
];
function isElementInViewportOrAbove($element) {
var viewportBottom = $window.scrollTop() + $window.height(),
elementTop = $element.offset().top;
return viewportBottom > (elementTop + $element.height());
}
function animate(element) {
element.addClass('animation');
}
window.on('scroll', function () {
// http://stackoverflow.com/questions/24812930/how-to-remove-element-from-array-in-foreach-loop
elements.forEach(function (element, index) {
if (shouldBeAnimated(element)) {
animate(element);
elements.splice(index, 1);
}
});
});