0

I am trying to get this function

var rotations = 0
function planet1rotate{
    rotations = rotations + 1
    document.getElementById('rotate').innerHTML = rotations
}

to play after this animation

    @keyframes spin-right {
        100% {transform: rotate(360deg);}
    }

here is the whole code, if it helps

<html>
<head>
<title></title>
<style type="text/css">
    #star{
        position: absolute;
        top: 50%;
        left: 50%;
        height: 100px;
        width: 100px;
        margin-top: -50px;
        margin-left: -50px;
        border-radius: 50%;
        background-color: red;
        animation: spin-right 2s linear infinite;  
    }
    @keyframes spin-right {
        100% {transform: rotate(360deg);}
    }
    #planet1{
        background-color: red;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        margin-top: -50px;
        margin-left: -50px;
    }
</style>
</head>
<body>
<script type="text/javascript">
    var rotations = 0
    function planet1rotate{
        rotations = rotations + 1
        document.getElementById('rotate').innerHTML = rotations
    }
</script>
<h1 id="rotate"></h1>
<div id="star">
    <div id="planet1"></div>
</div>
</body>
</html>

1 Answer 1

4

Check out the animation end event:

const animated = document.querySelector('.animated');

animated.addEventListener('animationend', () => {
  console.log('Animation ended');
});

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/animationend_event

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.