PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.7
Easy Elements for Elementor – Addons & Website Templates v1.3.7
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / counter / js / counter.js

counter.js in Easy Elements for Elementor – Addons & Website Templates 1.3.7, at widgets/counter/js/counter.js

66 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 "use strict";
3
4 function eelRunCounter($scope) {
5 const counters = $scope.find(".eel-counter");
6 if (!counters.length) return;
7
8 const observer = new IntersectionObserver(entries => {
9 entries.forEach(entry => {
10 if (!entry.isIntersecting) return;
11
12 const counter = entry.target;
13 observer.unobserve(counter);
14
15 const target = parseInt(counter.dataset.count, 10) || 0;
16 const duration = parseInt(counter.dataset.duration, 10) || 1000;
17 const format = counter.dataset.format || "default";
18
19 let current = 0;
20 const startTime = performance.now();
21
22 function formatNumber(num) {
23 if (num < 1000) return num;
24
25 const groups = num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, {
26 comma: ",",
27 dot: ".",
28 space: " ",
29 underline: "_"
30 }[format] || "");
31
32 return format === "underline" ? `${groups}` : groups;
33 }
34
35 function animate(time) {
36 const progress = Math.min((time - startTime) / duration, 1);
37 current = Math.floor(progress * target);
38
39 if (format === "underline") {
40 counter.innerHTML = formatNumber(current);
41 } else {
42 counter.textContent = formatNumber(current);
43 }
44
45 if (progress < 1) requestAnimationFrame(animate);
46 }
47
48 requestAnimationFrame(animate);
49 });
50 }, { threshold: 0.2 });
51
52 counters.each(function () {
53 observer.observe(this);
54 });
55 }
56
57 $(window).on("elementor/frontend/init", function () {
58 elementorFrontend.hooks.addAction("frontend/element_ready/widget", function ($scope) {
59 if ($scope.find(".eel-counter").length) {
60 eelRunCounter($scope);
61 }
62 });
63 });
64
65 })(jQuery);
66