counter-1.php
100 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly. |
| 4 | } |
| 5 | ?> |
| 6 | <div class="counters-container"> |
| 7 | <?php |
| 8 | if ( ! empty( $settings['counter_value'] ) ) { |
| 9 | ?> |
| 10 | <div class="skill_item ezd-text-center"> |
| 11 | <svg class="radial-progress" data-percentage="<?php echo $settings['counter_value']; ?>" |
| 12 | viewBox="0 0 80 80"> |
| 13 | <circle class="incomplete" cx="40" cy="40" r="35"></circle> |
| 14 | <circle class="complete" cx="40" cy="40" r="35"></circle> |
| 15 | |
| 16 | <div class="counter-wrap"> |
| 17 | <?php |
| 18 | if ( ! empty( $settings['counter_prefix'] ) ) { |
| 19 | ?> |
| 20 | <span class="counter-prefix"> |
| 21 | <?php echo $settings['counter_prefix']; ?> |
| 22 | </span> |
| 23 | <?php |
| 24 | } |
| 25 | ?> |
| 26 | <text class="percentage" x="50%" y="57%" transform="matrix(0, 1, -1, 0, 80, 0)"> |
| 27 | <?php echo $settings['counter_value']; ?> |
| 28 | </text> |
| 29 | <?php |
| 30 | if ( ! empty( $settings['counter_suffix'] ) ) { |
| 31 | ?> |
| 32 | <span class="counter-suffix"> |
| 33 | <?php echo $settings['counter_suffix']; ?> |
| 34 | </span> |
| 35 | <?php |
| 36 | } |
| 37 | ?> |
| 38 | </div> |
| 39 | </svg> |
| 40 | </div> |
| 41 | <?php |
| 42 | } |
| 43 | if ( ! empty( $settings['counter_text'] ) ) { |
| 44 | ?> |
| 45 | <h6 class="spel_counter_title"> |
| 46 | <?php echo $settings['counter_text']; ?> |
| 47 | </h6> |
| 48 | <?php |
| 49 | } |
| 50 | ?> |
| 51 | </div> |
| 52 | |
| 53 | <script type=text/javascript> |
| 54 | document.addEventListener("DOMContentLoaded", function () { |
| 55 | "use strict"; |
| 56 | |
| 57 | // Remove svg.radial-progress .complete inline styling |
| 58 | var radialProgressElements = document.querySelectorAll("svg.radial-progress"); |
| 59 | radialProgressElements.forEach(function (element) { |
| 60 | var completeCircle = element.querySelector("circle.complete"); |
| 61 | if (completeCircle) { |
| 62 | completeCircle.removeAttribute("style"); |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | window.addEventListener("scroll", function () { |
| 67 | radialProgressElements.forEach(function (element) { |
| 68 | // If svg.radial-progress is approximately 25% vertically into the window when scrolling from the top or the bottom |
| 69 | var rect = element.getBoundingClientRect(); |
| 70 | var windowHeight = window.innerHeight || document.documentElement.clientHeight; |
| 71 | if ( |
| 72 | rect.top <= windowHeight * 0.75 && |
| 73 | rect.bottom >= windowHeight * 0.25 |
| 74 | ) { |
| 75 | // Get percentage of progress |
| 76 | var percent = parseInt(element.getAttribute("data-percentage")); |
| 77 | |
| 78 | // Get radius of the svg's circle.complete |
| 79 | var completeCircle = element.querySelector("circle.complete"); |
| 80 | if (completeCircle) { |
| 81 | var radius = parseInt(completeCircle.getAttribute("r")); |
| 82 | |
| 83 | // Get circumference (2πr) |
| 84 | var circumference = 2 * Math.PI * radius; |
| 85 | |
| 86 | // Get stroke-dashoffset value based on the percentage of the circumference |
| 87 | var strokeDashOffset = circumference - (percent * circumference) / 100; |
| 88 | |
| 89 | // Transition progress for 1.25 seconds |
| 90 | completeCircle.style.transition = "stroke-dashoffset 1.25s"; |
| 91 | completeCircle.style.strokeDashoffset = strokeDashOffset; |
| 92 | } |
| 93 | } |
| 94 | }); |
| 95 | }); |
| 96 | |
| 97 | // Trigger scroll event to initialize animations |
| 98 | window.dispatchEvent(new Event("scroll")); |
| 99 | }); |
| 100 | </script> |