Answer the question
In order to leave comments, you need to log in
How to rotate using JS?
Good day.
Trying to make just one rotation of an image using JS
Original here: jsfiddle.net/JydNZ/51
$(document).ready(function(){
$('#icon').toggle(function(){
$(this).css("-webkit-transform","rotate(360deg)");
}, function(){
$(this).css("-webkit-transform","rotate(90deg)");
});
});
Answer the question
In order to leave comments, you need to log in
$(document).ready(function(){
var i = 1
$('#icon').click(function(){
$(this).css("-webkit-transform","rotate("+i*360+"deg)");
i++;
});
});
I suggest making css animation instead of using js
.target:hover,
.target:active{
animation: rotate 0.5s ease-in-out;
}
keyframes rotate{
to{
transform:rotate(360deg);
}
}
Something like this: jsfiddle.net/IonDen/o4kbgvoy
$(document).ready(function(){
$('#icon').on('click', function(){
var $this = $(this);
if ($this.hasClass('animated')) {
return;
}
$this.addClass('animated');
$this.css("transform","rotate(360deg)");
setTimeout(function () {
$this.removeClass('animated');
$this.css("transform","rotate(0deg)");
}, 800);
});
});
#icon{
overflow:hidden;
}
.animated {
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
-o-transition-duration: 0.8s;
transition-duration: 0.8s;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
transition-property: transform;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question