2
Я хочу повернуть изображение, но у меня нет вращения изображения. Как это исправить?Без анимации при использовании requestAnimationFrame в javascript
HTML файл:
<html>
<head>
<title>javascript</title>
</head>
<body>
<p style="text-align: center" >
<img src="kalam.jpg" style="position: relative">
</p>
<script type="text/javascript" src="code.js">
</script>
</body>
</html>
code.js:
var kalam = document.querySelector ("img") ;
var angle = 0 , lastTime = null ;
function animate (time) {
if (lastTime != null)
angle += (time - lastTime) * 0.001;
lastTime = time ;
kalam.style.top = (Math.sin (angle) * 20) + " px ";
kalam.style.left = (Math.cos (angle) * 200) + " px ";
requestAnimationFrame (animate) ;
}
requestAnimationFrame (animate);