Answers for "javascript restart css animation"

0

javascript restart css animation

<style>
	/* The element to apply the animation to */
	div { animation: example 2s; }

	/* animation keyframe */
	@keyframes example {
		0% { background-color: red; }
		100% { background-color: blue; }
	}
</style>

<!-- element example -->
<div id="aa">hello</div>

<!-- restart animation button -->
<button onclick="restart()">restary animation</button>

<script>
	// restart function 
	function restart() {
		document.getElementById("aa").style.animation = 'none';
		setTimeout(() => {
			document.getElementById("aa").style.animation = '';
		}, 0);
	}
</script>
Posted by: Guest on June-16-2021

Browse Popular Code Answers by Language