I want a div tag in html to rotate, when I click on that. Here is my code
$(document).on('click', '.rotate', function() {
degrees = 0;
while (degrees >= (-1080)) {
$(this).css({
'transform': 'rotate(' + degrees + 'deg)'
}).css({
'transition': '3s'
});
degrees--;
}
});
.rotate {
position: relative;
width: 200px;
height: 200px;
border-radius: 50%;
background: linear-gradient(magenta, blue, cyan, magenta);
margin: 100px auto;
line-height: 100px;
cursor: pointer;
border: 1px solid #fff;
}
.center {
width: 30px;
height: 30px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
border-radius: 50%;
box-shadow: 0 0 3px 3px rgba(0, 0, 0, 0.7);
z-index: 5;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="rotate">
<div class="center"></div>
</div>
It works good on first click. But in second and later clicks it doesn't. I don't know why this is happening.