/* Funkcja do odliczania */
function animateCount($element, duration = 3000)
{
var isPercent = $element.text().includes('%');
var target = parseFloat($element.data('number'));
$({ countNum: 0 }).animate({ countNum: target },
duration: duration,
easing: 'swing',
step: function(now){
$element.text(isPercent ? Math.floor(now) + '%' : Math.floor(now));
}, complete: function()
$element.text(isPercent ? target + '%' : target);
}
});
// Przypisanie funkcji animate + aktywacja jeśli element w viewport
function startCount
var $numbersSection = $('.licznik');
if ($numbersSection.length === 0) return;
$numbersSection.find('.number').each(function()
var $this = $(this);
$this.text('0' + ($this.text().includes('%') ? '%' : ''));
let counted = false;
const observer = new IntersectionObserver((entries) =>
entries.forEach(entry =>
if (entry.isIntersecting && !counted)
$numbersSection.find('.number').each(function(index) {
setTimeout(function()
animateCount($this);
}, index * 300);
counted = true;
observer.disconnect();
}, { threshold: 0.2 }); // 0.2 = 20% sekcji w widoku
observer.observe($numbersSection[0]);
$(document).ready(function()
//inicjalizacja funkcji
startCount();