-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise4-spinning-cube
More file actions
59 lines (59 loc) · 2.07 KB
/
exercise4-spinning-cube
File metadata and controls
59 lines (59 loc) · 2.07 KB
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
var cube = document.createElement('div');
cube.style.width = '100px';
cube.style.height = '100px';
cube.style.position = 'absolute';
cube.style.top = '50%';
cube.style.left = '50%';
cube.style.marginLeft = '-50px';
cube.style.marginTop = '-50px';
cube.style.webkitTransformStyle = 'preserve-3d';
cube.style.webkitTransform = 'rotateX(0deg) rotateY(0deg)';
cube.style.webkitTransition = '-webkit-transform 1s linear';
var face = document.createElement('div');
face.style.width = '100px';
face.style.height = '100px';
face.style.position = 'absolute';
face.style.backgroundColor = 'red';
face.style.webkitTransform = 'translateZ(50px)';
cube.appendChild(face);
face = document.createElement('div');
face.style.width = '100px';
face.style.height = '100px';
face.style.position = 'absolute';
face.style.backgroundColor = 'blue';
face.style.webkitTransform = 'rotateY(90deg) translateZ(50px)';
cube.appendChild(face);
face = document.createElement('div');
face.style.width = '100px';
face.style.height = '100px';
face.style.position = 'absolute';
face.style.backgroundColor = 'green';
face.style.webkitTransform = 'rotateY(180deg) translateZ(50px)';
cube.appendChild(face);
face = document.createElement('div');
face.style.width = '100px';
face.style.height = '100px';
face.style.position = 'absolute';
face.style.backgroundColor = 'yellow';
face.style.webkitTransform = 'rotateY(-90deg) translateZ(50px)';
cube.appendChild(face);
face = document.createElement('div');
face.style.width = '100px';
face.style.height = '100px';
face.style.position = 'absolute';
face.style.backgroundColor = 'orange';
face.style.webkitTransform = 'rotateX(90deg) translateZ(50px)';
cube.appendChild(face);
face = document.createElement('div');
face.style.width = '100px';
face.style.height = '100px';
face.style.position = 'absolute';
face.style.backgroundColor = 'purple';
face.style.webkitTransform = 'rotateX(-90deg) translateZ(50px)';
cube.appendChild(face);
document.body.appendChild(cube);
var angle = 0;
setInterval(function() {
cube.style.webkitTransform = 'rotateX(' + angle + 'deg) rotateY(' + angle + 'deg)';
angle += 1;
}, 100);