I am looking to dynamically change the top value of the keyframes based on a JavaScript variable x.
While I have experience changing CSS with JavaScript, this particular challenge has me stumped.
Code:
var x = Math.floor((Math.random() * 1080) + 1);
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
-webkit-animation-name: example; /* Safari 4.0 - 8.0 */
-webkit-animation-duration: 4s; /* Safari 4.0 - 8.0 */
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
0% {left:0px; top:300px}
100% {left:830px; top:0px}
}
<div></div>