.


Divya


How to rotate image in jQuery with demo


<!Doctype html>
<html>
<head>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<br>
<div class="w3-center"><img src="php.jpg" id="rotate-image" height="150px" width="150px"/></div>
<br>
<div class="w3-center">
<input type="button" class="w3-btn w3-green" value="90" onClick="rotateImage(this.value);" />
<input type="button" class="w3-btn w3-green" value="-90" onClick="rotateImage(this.value);" />
<input type="button" class="w3-btn w3-green" value="180" onClick="rotateImage(this.value);" />
<input type="button" class="w3-btn w3-green" value="360" onClick="rotateImage(this.value);" />
</div>
<script>
function rotateImage(degree) {
$('#rotate-image').animate({ transform: degree }, {
step: function(now,fx) {
$(this).css({
'-webkit-transform':'rotate('+now+'deg)',
'-moz-transform':'rotate('+now+'deg)',
'transform':'rotate('+now+'deg)'
});
}
});
}
</script>
</body>
</html>

Demo




.