Hello, coders. In this post, we will create an analog clock with completely HTML, CSS, and Javascript. Just copy the below code and paste it on index.html, style.css, main.js file respectively.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analog clock</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="clock">
<div class="wrap">
<span class="hour"></span>
<span class="minute"></span>
<span class="second"></span>
<span class="dot"></span>
</div>
</div>
</body>
<script src="main.js"></script>
</html>
CSS CODE:
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background: skyblue;
}
.clock {
border-radius: 100%;
background: #ffffff;
font-family: "Montserrat";
border: 5px solid white;
box-shadow: inset 2px 3px 8px 0 rgba(0, 0, 0, 0.1);
}
.wrap {
overflow: hidden;
position: relative;
width: 350px;
height: 350px;
border-radius: 100%;
}
.minute,
.hour {
position: absolute;
height: 100px;
width: 6px;
margin: auto;
top: -27%;
left: 0;
bottom: 0;
right: 0;
background: black;
transform-origin: bottom center;
transform: rotate(0deg);
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.4);
z-index: 1;
}
.minute {
position: absolute;
height: 130px;
width: 4px;
top: -38%;
left: 0;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.4);
transform: rotate(90deg);
}
.second {
position: absolute;
height: 90px;
width: 2px;
margin: auto;
top: -26%;
left: 0;
bottom: 0;
right: 0;
border-radius: 4px;
background: #FF4B3E;
transform-origin: bottom center;
transform: rotate(180deg);
z-index: 1;
}
.dot {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 12px;
height: 12px;
border-radius: 100px;
background: white;
border: 2px solid #1b1b1b;
border-radius: 100px;
margin: auto;
z-index: 1;
}
Js Code.
var inc = 1000;
clock();
function clock() {
const date = new Date();
const hours = ((date.getHours() + 11) % 12 + 1);
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const hour = hours * 30;
const minute = minutes * 6;
const second = seconds * 6;
document.querySelector('.hour').style.transform = `rotate(${hour}deg)`
document.querySelector('.minute').style.transform = `rotate(${minute}deg)`
document.querySelector('.second').style.transform = `rotate(${second}deg)`
}
setInterval(clock, inc);
And, that's it. Now run it and you will see a result like this.
Merkur's Merkur 23C Merkur 23C Review - SegaCasino.com
ReplyDeleteIn terms of safety, this หารายได้เสริม is a very basic safety razor, but you'll also 메리트 카지노 먹튀 find 메리트 카지노 가입 쿠폰 a full range of features. 나비효과 The Merkur 샌즈 카지노 총판 23C features an attractive handle Rating: 4.7 · Review by Jeff Grant