PluginProbe ʕ •ᴥ•ʔ
Spider Elements – Premium Elementor Widgets & Addons Library / 1.5.0
Spider Elements – Premium Elementor Widgets & Addons Library v1.5.0
trunk 1.0.0 1.1.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.7.0 1.8.0 1.9.0
spider-elements / widgets / templates / counter / counter-2.php
spider-elements / widgets / templates / counter Last commit date
counter-1.php 1 year ago counter-2.php 1 year ago
counter-2.php
128 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5 ?>
6
7 <div class="skill_item skill_item_two ezd-text-center">
8 <?php
9 if ( ! empty( $settings['counter_value'] ) ) {
10 ?>
11 <div class="skill_pr">
12 <svg class="radial-progress" data-percentage="<?php echo $settings['counter_value']; ?>"
13 viewBox="0 0 80 80">
14 <circle class="incomplete" cx="40" cy="40" r="35"></circle>
15 <circle class="complete" cx="40" cy="40" r="35"></circle>
16 </svg>
17 <div class="counter2-wrap">
18 <?php
19 if ( ! empty( $settings['counter_prefix'] ) ) {
20 ?>
21 <span class="counter-prefix">
22 <?php echo $settings['counter_prefix']; ?>
23 </span>
24 <?php
25 }
26 ?>
27 <span class="percentage counter">
28 <?php echo $settings['counter_value']; ?>
29 </span>
30 <?php
31 if ( ! empty( $settings['counter_suffix'] ) ) {
32 ?>
33 <span class="counter-suffix">
34 <?php echo $settings['counter_suffix']; ?>
35 </span>
36 <?php
37 }
38 ?>
39 </div>
40
41 </div>
42 <?php
43 }
44 if ( ! empty( $settings['counter_text'] ) ) {
45 ?>
46 <h6 class="spel_counter_title">
47 <?php echo $settings['counter_text']; ?>
48 </h6>
49 <?php
50 }
51 ?>
52 </div>
53
54 <script type=text/javascript>
55 ;(function ($) {
56 "use strict";
57
58 $(document).ready(function () {
59
60 // Remove svg.radial-progress .complete inline styling
61 var radialProgressElements = document.querySelectorAll("svg.radial-progress");
62 radialProgressElements.forEach(function (element) {
63 var completeCircle = element.querySelector("circle.complete");
64 if (completeCircle) {
65 completeCircle.removeAttribute("style");
66 }
67 });
68
69 function animateCounter(element, targetValue, duration) {
70 var startTime;
71 var initialValue = 0;
72
73 function updateCounter(timestamp) {
74 if (!startTime) startTime = timestamp;
75 var progress = timestamp - startTime;
76 var percentage = Math.min(progress / duration, 1);
77 var currentValue = Math.floor(initialValue + percentage * (targetValue - initialValue));
78 element.innerText = currentValue + "%";
79
80 if (percentage < 1) {
81 requestAnimationFrame(updateCounter);
82 }
83 }
84
85 requestAnimationFrame(updateCounter);
86 }
87
88 //animateCounter(document.querySelector(".skill_item_two .counter"), <?php echo esc_html( $counter_value ) ?>, 1000
89
90 window.addEventListener("scroll", function () {
91 radialProgressElements.forEach(function (element) {
92 // If svg.radial-progress is approximately 25% vertically into the window when scrolling from the bottom to the top
93 var rect = element.getBoundingClientRect();
94 var windowHeight = window.innerHeight || document.documentElement
95 .clientHeight;
96 if (rect.top <= windowHeight * 0.75 && rect.bottom >= windowHeight * 0.25) {
97 // Get percentage of progress
98 var percent = parseInt(element.getAttribute("data-percentage"));
99
100 // Get radius of the svg's circle.complete
101 var completeCircle = element.querySelector("circle.complete");
102 if (completeCircle) {
103 var radius = parseInt(completeCircle.getAttribute("r"));
104
105 // Get circumference (2πr)
106 var circumference = 2 * Math.PI * radius;
107
108 // Get stroke-dashoffset value based on the percentage of the circumference
109 var strokeDashOffset = circumference - (percent * circumference) /
110 100;
111
112 // Transition progress for 1.25 seconds
113 completeCircle.style.transition = "stroke-dashoffset 1.25s";
114 completeCircle.style.strokeDashoffset = strokeDashOffset;
115
116 // Animate counterUp
117 }
118 }
119 });
120 });
121
122 // Trigger scroll event to initialize animations
123 window.dispatchEvent(new Event("scroll"));
124
125 });
126
127 })(jQuery);
128 </script>