-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (60 loc) · 2.54 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const progressCircles = document.querySelectorAll('.progress-circle');
const animateProgress = (circle) => {
const progress = circle.getAttribute('data-progress');
const offset = 314 - (progress / 100 * 314); // 314 is the circumference of the circle (2 * Math.PI * 110)
const progressCircle = circle.querySelector('.progress');
progressCircle.style.strokeDashoffset = offset;
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const circle = entry.target;
animateProgress(circle);
observer.unobserve(circle); // Stop observing after animation
}
});
}, { threshold: 0.5 }); // Trigger when 50% of the circle is in view
progressCircles.forEach(circle => {
observer.observe(circle);
});
new CircleProgress('.progress', {
max: 100,
value: 60,
textFormat: 'percent',
});
document.addEventListener("DOMContentLoaded", function() {
const container = document.querySelector(".progress-container");
const progressText = container.querySelector(".progress-text");
const progressCircle = container.querySelector(".progress-circle");
// Extract values from custom properties
const size = parseFloat(getComputedStyle(container).getPropertyValue("--size")) || 200;
const strokeWidth = parseFloat(getComputedStyle(container).getPropertyValue("--stroke-width")) || 8;
const percentage = parseFloat(getComputedStyle(container).getPropertyValue("--percentage")) || 41;
const color = getComputedStyle(container).getPropertyValue("--color") || "#1a1a2e";
const center = size / 2;
const radius = center - strokeWidth / 2;
const circumference = 2 * Math.PI * radius;
// Set up the SVG and styles
progressCircle.setAttribute("r", radius);
progressCircle.setAttribute("cx", center);
progressCircle.setAttribute("cy", center);
progressCircle.setAttribute("stroke-width", strokeWidth);
progressCircle.setAttribute("stroke-dasharray", circumference);
progressCircle.style.stroke = color;
// Animate the progress
let progress = 0;
const animateProgress = () => {
if (progress < percentage) {
progress += 1;
const offset = circumference - (progress / 100) * circumference;
progressCircle.setAttribute("stroke-dashoffset", offset);
progressText.textContent = `${progress}%`;
requestAnimationFrame(animateProgress);
}
};
animateProgress();
});
$(function() {
AOS.init();
});
window.addEventListener('load', AOS.refresh)