I've been trying to make a page where if you press a button it triggers an animation but it seems that it will only play once and I can't seem to figure out a way to reset it so I can play it again.
<!DOCTYPE html>
<html>
<head>
<style>
body{
background: pink;
}
#object {
background: cyan;
height: 100px;
width: 100px;
text-align: center;
}
@keyframes spin {
from {
rotate: 0deg;
}
to {
rotate: 360deg;
}
}
</style>
</head>
<body>
<div id="object"><p>-w-</p></div>
<button onclick="playanim()" id="button">play</button>
<script type="text/javascript">
var obj = document.getElementById("object")
function playanim() {
obj.style.animation = null // <-- I want to reset the animation when pressing the button to play it again.
obj.style.animation = "spin 2s"
}
</script>
</body>
</html>
Anything helps! Thank you.