jQuery toggleClass example
Toggle class name on click in jQuery
by denisz
HTML
<div style="height: 2000px; width: 30px; background: red;">
</div>
<h3><span class="single count">20</span></h3>
<p>Länder</p>
JavaScript
var options = {
root: null,
rootMargin: '0px',
threshold: 1.0
}
var callback = function(entries, observer) {
entries.map(item => {
if(item.isIntersecting) {
$('.count').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
}
})
};
var observer = new IntersectionObserver(callback, options);
observer.observe(document.querySelector('.count'));