how can I make a counter that counts every time animation restarts? I tried seconds counter, but it didnt synchronize well with my animation. However, I am trying to make similar website as tacospin.com, but with jumping dog. The logic in tacospin is quite simple, everytime degree = 0 it counts. But I cant figure out how to do something like that My animation code:
var seconds = 0; var el = document.getElementById('seconds-counter'); function incrementSeconds() { seconds += 1; el.innerText = "You have been here for " + seconds + " seconds."; } var cancel = setInterval(incrementSeconds, 1350); #center{ display: block; margin-left: auto; margin-right: auto; width: 20%; } .centerfloor{ display: block; margin-left: auto; margin-right: auto; margin-top: 193px; width: 30%; } @keyframes jump { 0% {transform: translate3d(0,0,0) scale3d(1,1,1);} 40% {transform: translate3d(0,30%,0) scale3d(1,1,1);} 100% {transform: translate3d(0,100%,0) scale3d(1,1.2,1);} } .jump { transform-origin: 50% 50%; animation: jump .7s linear alternate infinite; } /* For demo: */ <!DOCTYPE html> <html lang="cz"> <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>Dog jump</title> <link rel="stylesheet" href="style.css"> </head> <body> <main> <div id="dogdiv"> <img class="jump" id="center" src="dogie.png" alt="idk"> </div> <img class="centerfloor" src="floo.png"> </main> <div id="seconds-counter"></div> <script src="script.js"></script> </body> </html>