I have just started to learn JavaScript and am trying to make an analog clock. First I have created the second meter with css. Then I am trying to convert it into JavaScript. I don't want to use any jQuery or any other JS framework for this.
How to set the css @keyframe in JavaScript? Here is my code for CSS:
.second{
height: 5px;
width: 180px;
background-color: #aaaaaa;
border-radius: 5px;
position: absolute;
top: 50%;
left: 50%;
-webkit-animation-name: spin;
-webkit-animation-duration: 60s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-o-transition: rotate(360deg);
transform-origin: left center;
z-index: 3;
}
@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
js code for this css
var second = document.querySelector(".second");
second.style.height = "5px";
second.style.width = "180px";
second.style.backgroundColor = "#aaaaaa";
second.style.borderRadius = "5px";
second.style.position = "absolute";
second.style.top = "50%";
second.style.left = "50%";
second.style.transformOrigin = "left center";
second.style.zIndex = "3";
second.style.webkitAnimationName = "Spin";
second.style.webkitAnimationDuration = "60s";
second.style.webkitAnimationIterationCount: "infinite"; //doesn't work
second.style.webkitAnimationTimingFunction: "linear"; //doesn't work
second.style.oTransition: "rotate(360deg)"; //doesn't work
rAF.