(function ($) { "use strict"; // Function to check if an element is in the viewport function isElementInViewport(el) { var rect = el.getBoundingClientRect(); return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth); } // Function to start counter animation when element is in viewport function startCounterAnimation() { $(".bizbloom-number-counter") .not(".counted") .each(function () { if (isElementInViewport(this)) { var $this = $(this); $this .addClass("counted") .prop("Counter", 0) .animate( { Counter: $this.text(), }, { duration: 1000, easing: "swing", step: function (now) { $this.text(Math.ceil(now)); }, } ); } }); } // Check if element is in viewport on page load $(document).ready(function () { startCounterAnimation(); }); // Check if element is in viewport on scroll $(window).on("scroll", function () { startCounterAnimation(); }); })(jQuery);