Cover Image for CSS Watch Animation
185 views

CSS Watch Animation

CSS animations can be used to create a wide variety of effects, including a watch animation. A watch animation typically involves the movement of watch hands, ticking, or other visual elements that mimic the behavior of a real watch. Here’s a basic example of a CSS watch animation:

Sure! Here’s an example of a CSS animation for a watch:

HTML:

<div class="watch">
  <div class="hour-hand"></div>
  <div class="minute-hand"></div>
  <div class="second-hand"></div>
</div>

CSS:

.watch {
  position: relative;
  width: 200px;
  height: 200px;
  border: 2px solid #000;
  border-radius: 50%;
  margin: 50px auto;
}

.hour-hand,
.minute-hand,
.second-hand {
  position: absolute;
  background-color: #000;
}

.hour-hand {
  width: 6px;
  height: 70px;
  top: 65px;
  left: 97px;
  transform-origin: bottom center;
  animation: hour-hand 12s infinite linear;
}

.minute-hand {
  width: 4px;
  height: 90px;
  top: 40px;
  left: 98px;
  transform-origin: bottom center;
  animation: minute-hand 60s infinite linear;
}

.second-hand {
  width: 2px;
  height: 100px;
  top: 30px;
  left: 99px;
  transform-origin: bottom center;
  animation: second-hand 60s infinite steps(60);
}

@keyframes hour-hand {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes minute-hand {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes second-hand {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

In this example, we create a watch using a <div> element with a circular shape and a border. Inside the watch, we create three <div> elements representing the hour hand, minute hand, and second hand. We position them using absolute positioning and set their dimensions.

To create the animation, we use CSS keyframes (@keyframes) to define the rotation transformation for each hand. We set the animation duration and timing function for each hand to control the speed and smoothness of the animation.

You can adjust the dimensions, colors, and animation properties according to your preference to customize the watch animation.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS