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>7-Segment Neon Digital CLock</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<main></main>
</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: inherit;
font-family: inherit;
}
html {
box-sizing: border-box;
font-size: 0.75vmin;
font-family: sans-serif;
}
body {
display: flex;
height: 100vh;
width: 100%;
background-image: linear-gradient(to bottom, #151515, #000000);
font-size: 1.5rem;
flex-direction: column;
justify-content: center;
align-items: center;
perspective: 45rem;
transform-style: preserve-3d;
overflow: hidden;
}
.wrapper {
height: 100%;
width: 100%;
transform-style: preserve-3d;
animation: cameraAnim 24s ease-in-out forwards infinite;
}
main {
position: relative;
display: flex;
height: 100%;
width: 100%;
color: hsl(213deg, 100%, 50%);
translate: 0rem 1rem 10rem;
transform-style: preserve-3d;
gap: 1rem;
justify-content: center;
align-items: center;
animation: cameraPanAnim 24s linear forwards infinite;
animation-composition: add;
}
main .digits {
transform-style: preserve-3d;
}
main .digits .group {
display: flex;
gap: 2rem;
}
main .digits .group .digit {
position: relative;
height: 16rem;
filter: drop-shadow(0px 0px 4px currentColor) drop-shadow(0px 0px 10px currentColor);
aspect-ratio: 1 / 2;
}
main .digits .group .digit span {
--act: 0;
--signX: 1;
--signY: 1;
position: absolute;
background-color: #ffffff;
transform: scale(var(--signX), var(--signY));
transition: all 0.24s cubic-bezier(0.15, 0.69, 0.51, 1.14);
opacity: calc(0.06 + 0.96 * var(--act));
animation-composition: add;
}
main .digits .group .digit span.end {
height: 10%;
width: 100%;
-webkit-clip-path: polygon(15% 0%, 7.5% 20%, 25% 100%, 75% 100%, 92.5% 20%, 85% 0%);
clip-path: polygon(15% 0%, 7.5% 20%, 25% 100%, 75% 100%, 92.5% 20%, 85% 0%);
}
main .digits .group .digit span.end.top {
top: 0;
}
main .digits .group .digit span.end.bottom {
--signY: -1;
top: initial;
bottom: 0;
}
main .digits .group .digit span.side {
height: 50%;
width: 20%;
-webkit-clip-path: polygon(0% 15%, 20% 7.5%, 100% 22.5%, 100% 85%, 20% 95%, 0% 90%);
clip-path: polygon(0% 15%, 20% 7.5%, 100% 22.5%, 100% 85%, 20% 95%, 0% 90%);
}
main .digits .group .digit span.side.left {
top: 0;
left: 0;
}
main .digits .group .digit span.side.left.bottom {
--signY: -1;
top: initial;
bottom: 0;
}
main .digits .group .digit span.side.right {
--signX: -1;
top: 0;
left: initial;
right: 0;
}
main .digits .group .digit span.side.right.bottom {
--signY: -1;
top: initial;
bottom: 0;
}
main .digits .group .digit span.middle {
top: 45%;
height: 10%;
width: 100%;
-webkit-clip-path: polygon(22.5% 0%, 6.5% 50%, 22.5% 100%, 77.5% 100%, 93.5% 50%, 77.5% 0%);
clip-path: polygon(22.5% 0%, 6.5% 50%, 22.5% 100%, 77.5% 100%, 93.5% 50%, 77.5% 0%);
}
main .digits .group .digit[data-digit="0"] :not(.middle), main .digits .group .digit[data-digit="1"] .right,
main .digits .group .digit[data-digit="2"] :not(.top.left, .bottom.right), main .digits .group .digit[data-digit="3"] :not(.left),
main .digits .group .digit[data-digit="4"] :not(.end, .bottom.left), main .digits .group .digit[data-digit="5"] :not(.top.right, .bottom.left),
main .digits .group .digit[data-digit="6"] :not(.top.right), main .digits .group .digit[data-digit="7"] .top,
main .digits .group .digit[data-digit="7"] .right, main .digits .group .digit[data-digit="8"]>*,
main .digits .group .digit[data-digit="9"] :not(.bottom.left) {
--act: 1;
}
main .colon-group {
transform-style: preserve-3d;
}
main .colon-group .colon span {
display: flex;
height: 16rem;
width: 4rem;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
filter: drop-shadow(0px 0px 4px currentColor) drop-shadow(0px 0px 10px currentColor);
}
main .colon-group .colon span::before, main .colon-group .colon span::after {
content: "";
display: block;
width: 2rem;
background-color: #ffffff;
border-radius: 2rem;
aspect-ratio: 1 / 1;
}
main .shadow {
position: absolute;
top: 0;
transform: translateY(1rem) translateZ(2rem) rotateX(-90.1deg);
transform-origin: bottom center;
}
main .shadow .digit span {
opacity: var(--act);
}
main .shadow.shadow1 {
opacity: 0.5;
filter: drop-shadow(0px 0px 4px currentColor) drop-shadow(0px 0px 10px currentColor) blur(4rem);
}
main .shadow.shadow1>span, main .shadow.shadow1 .digit {
-webkit-mask-image: linear-gradient(to bottom, #ffffff, #00000080);
mask-image: linear-gradient(to bottom, #ffffff, #00000080);
}
main .shadow.shadow2 {
opacity: 0.4;
filter: drop-shadow(0px 0px 4px currentColor) drop-shadow(0px 0px 10px currentColor) blur(4px);
}
main .shadow.shadow2>span, main .shadow.shadow2 .digit {
opacity: var(--act);
-webkit-mask-image: linear-gradient(to top, #000000, #0000001a 60%, transparent);
mask-image: linear-gradient(to top, #000000, #0000001a 60%, transparent);
}
@keyframes cameraAnim {
0%, 100% {
transform: rotateY(-10deg);
}
50% {
transform: rotateY(10deg);
}
}
@keyframes cameraPanAnim {
0%, 100% {
transform: translate(0rem, 0rem);
}
20% {
transform: translate(1rem, 2rem);
}
40% {
transform: translate(-2rem, 2.5rem);
}
50% {
transform: translate(-1.5rem, 1.5rem);
}
70% {
transform: translate(-0.5rem, -0.5rem);
}
90% {
transform: translate(1.5rem, -1rem);
}
}
Below is the javascript code for this video.
index.js
const bars = [["end", "top"], ["side", "top", "left"], ["side", "top", "right"], ["middle"],
["side", "bottom", "left"], ["side", "bottom", "right"], ["end", "bottom"]];
const main = document.querySelector("main");
const addDigits = (number) => {
const initGroup = (number, padding = 2) => {
const group = document.createElement("div");
group.classList.add("group");
const digits = [...`${number}`.padStart(padding, 0)].map((digit) => {
const digitElement = document.createElement("figure");
digitElement.classList.add("digit");
digitElement.setAttribute("data-digit", digit);
bars.forEach((classes) => {
const span = document.createElement("span");
span.classList.add(...classes);
digitElement.appendChild(span);
});
return digitElement;
});
group.append(...digits);
return {
element: group,
set number(val) {
number = val;
[...`${number}`.padStart(padding, 0).slice(-padding)].forEach((digit, i) => {
digits[i].setAttribute("data-digit", digit);
});
},
get number() { return number; }
};
};
const digitsContainer = document.createElement("div");
digitsContainer.classList.add("digits");
const group = initGroup(number);
const groupShadow1 = initGroup(number);
const groupShadow2 = initGroup(number);
groupShadow1.element.classList.add("shadow", "shadow1");
groupShadow2.element.classList.add("shadow", "shadow2");
digitsContainer.appendChild(group.element);
digitsContainer.appendChild(groupShadow1.element);
digitsContainer.appendChild(groupShadow2.element);
main.appendChild(digitsContainer);
return {
set number(val) {
number = val;
group.number = val;
groupShadow1.number = val;
groupShadow2.number = val;
},
get number() { return number; }
};
};
const addColon = () => {
const colonGroup = document.createElement("div");
colonGroup.classList.add("colon-group");
const createColonElement = () => {
const colon = document.createElement("figure");
colon.appendChild(document.createElement("span"));
return colon;
};
const colon = createColonElement();
const colonShadow1 = createColonElement();
const colonShadow2 = createColonElement();
colon.classList.add("colon");
colonShadow1.classList.add("colon", "shadow", "shadow1");
colonShadow2.classList.add("colon", "shadow", "shadow2");
colonGroup.appendChild(colon);
colonGroup.appendChild(colonShadow1);
colonGroup.appendChild(colonShadow2);
main.appendChild(colonGroup);
};
const init = () => {
let now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
const numberHour = addDigits(hours);
addColon();
const numberMinute = addDigits(minutes);
addColon();
const numberSecond = addDigits(seconds);
const update = () => {
now = new Date();
let newSeconds = now.getSeconds();
if (seconds !== newSeconds) {
hours = now.getHours();
minutes = now.getMinutes();
seconds = newSeconds;
numberHour.number = hours;
numberMinute.number = minutes;
numberSecond.number = seconds;
}
requestAnimationFrame(update);
};
update();
};
init();
Thanks for visiting