<script>
document.querySelector("body").addEventListener("keydown",venstre);
function venstre(e)
{
if (e.keyCode===37)
{
document.querySelector(".bil").style.animation = "venstre 1s linear forwards, venstre 1s"
window.setTimeout(kjørvens,0);
}
}
function kjørvens()
{
document.querySelector(".bil").style.animation = "venstre 1s linear forwards";
}
I thought I could make this animation repeat from where it was on every press of left arrow, as in holding it down and having my car move continously. sorry if im formatting my question weird or doing my code in the least usable way
You could use a css property animation-play-state to pause or resume your animation.
Here is the documentation you should check out: https://developer.mozilla.org/en-US/docs/Web/CSS/animation-play-state