-
Notifications
You must be signed in to change notification settings - Fork 0
/
360RotatingObject.html
70 lines (55 loc) · 1.76 KB
/
360RotatingObject.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>requestAnimationFrame spinner example</title>
<link href="img/ui/favicon.ico" type="image/x-icon" rel="icon">
<style>
html {
background-color: white;
height: 100%;
}
body {
height: inherit;
background-color: rgb(52, 190, 126);
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
div {
display: inline-block;
font-size: 10rem;
}
</style>
</head>
<body>
<h1>چرخیدن ۳۶۰ درجه شیء حول محور مرکزی توسط جاوا اسکریپت</h1>
<div>=</div>
<br>
<script>
// Store reference to the div element, create a rotate counter and null startTime
// and create an uninitialized variable to store the requestAnimationFrame() call in
const spinner = document.querySelector('div');
let rotateCount = 0;
let startTime = null;
let rAF;
// Create a draw() function
function draw(timestamp) {
if (!startTime) {
startTime = timestamp;
}
rotateCount = (timestamp - startTime) / 3;
// If rotateCount gets over 359, set it to 'remainder of dividing by 360'
if (rotateCount > 359) {
rotateCount %= 360;
}
// Set the rotation of the div to be equal to rotateCount degrees
spinner.style.transform = 'rotate(' + rotateCount + 'deg)';
// Call the next frame in the animation
rAF = requestAnimationFrame(draw);
}
draw();
</script>
</body>
</html>