Before Big refactor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Copyright John Salguero All rights Reserved
|
||||
const radius = 25;
|
||||
const radius = 30;
|
||||
const circumference = 2 * Math.PI * radius;
|
||||
const circle = document.getElementById("timer-progress");
|
||||
|
||||
@@ -15,6 +15,9 @@ let timerInterval = null;
|
||||
function startTimer(duration) {
|
||||
let timeLeft = duration;
|
||||
const textEl = document.getElementById("timer-text");
|
||||
textEl.textContent = timeLeft;
|
||||
circle.style.stroke = startColor;
|
||||
circle.style.strokeDashoffset = 0;
|
||||
|
||||
// clear previous timer
|
||||
if (timerInterval) {
|
||||
@@ -28,17 +31,18 @@ function startTimer(duration) {
|
||||
textEl.textContent = timeLeft;
|
||||
|
||||
// 🔥 recompute progress EVERY tick
|
||||
const progress = (duration - timeLeft) / duration;
|
||||
const progress = (duration - (timeLeft - 1)) / duration;
|
||||
const p = Math.max(0, Math.min(1, progress));
|
||||
|
||||
// update circle
|
||||
const offset = circumference * progress;
|
||||
const offset = circumference * p;
|
||||
circle.style.strokeDashoffset = -offset;
|
||||
|
||||
// color interpolation
|
||||
if (progress < 0.5) {
|
||||
circle.style.stroke = lerpColor(startColor, middleColor, progress * 2);
|
||||
circle.style.stroke = lerpColor(startColor, middleColor, p * 2);
|
||||
} else {
|
||||
circle.style.stroke = lerpColor(middleColor, endColor, (progress - 0.5) * 2);
|
||||
circle.style.stroke = lerpColor(middleColor, endColor, (p - 0.5) * 2);
|
||||
}
|
||||
|
||||
// low-time pulse
|
||||
|
||||
Reference in New Issue
Block a user