Greetings, I have the following div spinning with @Keyframes. What I need is that when you click on the same div, capture the current angle it is in.
const go = document.querySelector('#box');
const box = document.querySelector('.box');
const rpm = 30;
const timeout = 30;
let tid = null; // timeout id
const sec = 60 / parseInt(rpm);
const millisec = parseInt(timeout) * 1000;
$( document ).ready(function() {
rotate.stop();
rotate.start(sec, millisec);
});
go.addEventListener('click', () => {
//CAPUTA ANGULO ACTUAL DEL DIV BOX
});
const rotate = {
stop() {
if (tid) {
window.clearTimeout(tid);
}
box.removeAttribute('style');
box.classList.remove('animated');
},
start (sec, millisec) {
box.style.animationDuration = '${sec}s';
box.classList.add('animated');
tid = window.setTimeout(() => {
box.classList.remove('animated');
}, millisec);
}
}
html, body{
height: 100%;
width: 100%;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
.draw{
height: 15rem;
width: 15rem;
display: flex;
align-items: center;
justify-content: center;
}
.box {
width: 100%;
height: 100%;
background-color: aqua;
}
.box.animated {
animation-name: rotate;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section class="draw">
<div class="box" id="box"></div>
</section>
<script src="jquery.min.js"></script>
<script src="script3.js"></script>
</body>
</html>