The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Satisfying Abacus Clock</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="abacus-clock">
<div style="--color: #ff6961" data-beads="2"></div>
<div style="--color: #ff6961" data-beads="10"></div>
<div style="--color: #77dd77" data-beads="6"></div>
<div style="--color: #77dd77" data-beads="10"></div>
<div style="--color: #779ecb" data-beads="6"></div>
<div style="--color: #779ecb" data-beads="10"></div>
<time></time>
</div>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
*, *::after, *::before {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
height: 100vh;
width: 100%;
background: radial-gradient(circle, #99a09b80, #99a09b);
justify-content: center;
align-items: center;
overflow: hidden;
}
:root {
--max-beads: 10;
--min-beads-gap: 4;
--gradient: hsl(0 0% 100% / 0.24), hsl(0 0% 100% / 0.51) 24%, hsl(0 0% 0% / 0.51) 87%;
}
.abacus-clock {
position: relative;
display: grid;
width: min(30rem, 100%);
margin-inline: auto;
container-type: inline-size;
}
.abacus-clock::before, .abacus-clock::after {
content: "";
position: absolute;
top: 0;
height: 100%;
width: 5cqi;
background-color: #1d1c1a;
background-image: linear-gradient(90deg, var(--gradient));
border-radius: 5cqi 5cqi 0 0;
}
.abacus-clock::before {
left: 0;
}
.abacus-clock::after {
right: 0;
}
.abacus-clock>time {
width: 100%;
color: #ffffff;
font-size: 5cqi;
font-family: sans-serif;
text-align: center;
text-transform: uppercase;
margin-top: 6vh;
text-shadow: 1px 2px 3px #000000bf;
}
.abacus-clock>[data-beads] {
position: relative;
display: flex;
justify-content: flex-end;
margin-inline: 5cqi;
margin-block: 1cqi;
}
.abacus-clock>[data-beads]:first-of-type {
margin-top: 10cqi;
}
.abacus-clock>[data-beads]::before {
content: "";
position: absolute;
background-color: var(--color);
background-image: linear-gradient(var(--gradient));
inset: 40% 0;
z-index: -1;
}
.abacus-clock>[data-beads]>i {
width: calc(100% / (var(--max-beads) + var(--min-beads-gap, 1)));
background-color: var(--color);
background-image: linear-gradient(var(--gradient));
border-radius: 25%;
aspect-ratio: 1 / 1.5;
transition: transform 0.51s;
box-shadow: inset 0 -10px 10px hsl(0 0% 0% / 0.5);
}
.abacus-clock>[data-beads]>i[data-active="true"] {
transform: translateX(calc(-100% * (var(--max-beads) - var(--beads, var(--max-beads)) + var(--min-beads-gap, 1))));
}
Below is the javascript code for this video.
index.js
abacusClock(".abacus-clock");
function abacusClock(selector) {
const abacusClockRows = document.querySelectorAll(selector + ">[data-beads]");
const timeElement = document.querySelector(selector + ">time");
if (!abacusClockRows) return;
const digitElements = [];
abacusClockRows.forEach(digitElement => {
const beads = Number(digitElement.dataset.beads);
digitElement.style.setProperty("--beads", beads);
const beadElements = [];
digitElements.push(beadElements);
for (let i = 0; i < beads; i++) {
const beadElement = document.createElement("i");
digitElement.append(beadElement);
beadElements.push(beadElement);
}
});
time();
function time() {
const options = { hour12: true, hour: "2-digit", minute: "2-digit", second: "2-digit" };
const str = new Date().toLocaleTimeString([], options);
str.match(/\d/g).forEach((d, di) => digitElements[di].forEach((b, bi) => (b.dataset.active = bi < d)));
timeElement.dateTime = timeElement.innerHTML = str;
window.requestAnimationFrame(time);
}
}
Thanks for visiting