I've been trying to create a Nav using jQuery, and part of it is rotating a gear PNG, and I've looked here and found someone describing how to do it without a plugin, but i modified their code so instead of changing angle every click i changed it so that it changes angle from 0 to 180 with delay between each step hence the setTimeout function. anyhow here's the code.
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256- 16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"> </script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=" crossorigin="anonymous"></script>
<script src="main.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<div id="header">
<div id="gear">
<img src="gear.png">
</div>
</div>
</body>
</html>
CSS
#header {
position: relative;
}
#gear {
position: absolute;
left: 50px;
}
JS
$(document).ready(function() {
var rotDeg = 0;
var rotEnd = 180;
jQuery.fn.rotate = function(degrees) {
$(this).css({'-webkit-transform' : 'rotate('+ degrees +'deg)',
'-moz-transform' : 'rotate('+ degrees +'deg)',
'-ms-transform' : 'rotate('+ degrees +'deg)',
'transform' : 'rotate('+ degrees +'deg)'});
return $(this);
};
$('#gear').click(function() {
while(rotDeg <= rotEnd) {
setTimeout(function() {
rotDeg += 1;
$(this).rotate(rotDeg);
}, 34);
}
});
});