<div class="timer">
<div class="timer__progress"></div>
<p class="timer__text">Текст</p>
</div>
body {
min-height: 100vh;
margin: 0;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
font-size: 16px;
font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
}
.timer {
--progress: 100;
position: relative;
width: 200px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
&__progress {
--angle: calc(3.6deg * var(--progress, 0));
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: conic-gradient(#8cd2a2 var(--angle, 0deg), transparent var(--angle, 0deg));
clip-path: circle(50% at 50%);
}
&__text {
margin: 0;
font-size: 2.5em;
text-transform: uppercase;
opacity: 0.75;
z-index: 1;
}
}
View Compiled
const timer = document.querySelector('.timer');
const duration = 12000;
let startTime = 0;
const now = () => performance.now();
const update = () => {
const delta = now() - startTime;
const difference = duration - delta;
const percent = Math.max(0, Math.min(100, (difference / duration) * 100));
timer.style.setProperty('--progress', percent);
if (difference > 0) {
requestAnimationFrame(update);
}
};
const start = () => {
startTime = now();
requestAnimationFrame(update);
};
window.addEventListener('click', start);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.