There are many great code snippets in their Gitlab. You might find more on their…
Scroll Depth Indicator
jQuery(function($) {
$( document ).ready(function() {
if ($('.animatedCounter').length) {
$(window).scroll(testScroll);
}
});
var viewed = false;
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
function testScroll() {
if (isScrolledIntoView($(".animatedCounter")) && !viewed) {
viewed = true;
$('.animatedCounter').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 1000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
}
}
}(jQuery));
Dieser Beitrag hat 0 Kommentare