Clock | Html Css And JavaScript

HTML
<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CodeAtNow - Clock with a background gradient</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<div class="clock">
  <div class="hands">
    <div class="hour"></div>
    <div class="minute"></div>
    <div class="second"></div>
  </div>
</div>
<!-- partial -->
  <script  src="./script.js"></script>

</body>
</html>
CSS
html,
body {
  background: #f3f3f3;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

.clock {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #2e2c2f;
  width: 250px;
  height: 250px;
  border-radius: 50%;
}

.hands {
  position: relative;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
}

.hour,
.minute,
.second {
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  transform: rotate(0deg);
  transform-origin: bottom center;
  width: 4px;
  border-radius: 2px;
}

.hour {
  background: whitesmoke;
  height: 50px;
  top: -20%;
}

.minute {
  background: whitesmoke;
  height: 90px;
  top: -36%;
}

.second {
  background: #ff0f7b;
  width: 2px;
  height: 80px;
  top: -32%;
}

.clock:before {
  content: "";
  z-index: -1;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(-45deg, #295df8 0%, #ff0f7b 100%);
  transform: translate3d(0px, 20px, 0) scale(1.2);
  filter: blur(40px);
  opacity: var(0.8);
  transition: opacity 0.3s;
  border-radius: inherit;
  -webkit-animation: blobby 5s infinite ease;
          animation: blobby 5s infinite ease;
}

.clock:after {
  content: "";
  z-index: -1;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: inherit;
  border-radius: inherit;
}

@-webkit-keyframes blobby {
  0% {
    transform: translate3d(0px, 20px, 0) scale(1.2);
  }
  20% {
    transform: translate3d(0px, 10px, 0) scale(0.9) rotate(20deg);
  }
  50% {
    transform: translate3d(0px, 20px, 0) scale(1) rotate(0deg);
  }
  70% {
    transform: translate3d(0px, 10px, 0) scale(1.4) rotate(20deg);
  }
  0% {
    transform: translate3d(0px, 20px, 0) scale(1.2);
  }
}

@keyframes blobby {
  0% {
    transform: translate3d(0px, 20px, 0) scale(1.2);
  }
  20% {
    transform: translate3d(0px, 10px, 0) scale(0.9) rotate(20deg);
  }
  50% {
    transform: translate3d(0px, 20px, 0) scale(1) rotate(0deg);
  }
  70% {
    transform: translate3d(0px, 10px, 0) scale(1.4) rotate(20deg);
  }
  0% {
    transform: translate3d(0px, 20px, 0) scale(1.2);
  }
}
JS
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, 1000);

Follow Us On Telegram  

Get Full Source Code Zipped File  

Telegram link

Post a Comment

0Comments
Post a Comment (0)