-
Notifications
You must be signed in to change notification settings - Fork 0
/
addTest.html
141 lines (123 loc) · 4.58 KB
/
addTest.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head lang="ko">
<meta charset="UTF-8">
<title></title>
<link href="aniTest.scss" rel="stylesheet" type="text/css">
<script src="fps.js"></script>
</head>
<body>
<div id="fps" style="position: fixed;right:0;top:0;background: red;color:#fff">
</div>
<div class="area">
<button type="button" class="play">Play</button>
<div class="obj" style="-webkit-transform:translate3d(100px,80px,0)">
</div>
<script>
var playBtn = document.querySelector(".play");
var obj = document.querySelector(".obj");
var matrix = new WebKitCSSMatrix(window.getComputedStyle(obj,null).webkitTransform).m41
playBtn.onclick = function() {
var speed = null;
var startX = new Date().getTime();
var go = setTimeout(function(){
speed = matrix/20;
matrix += Math.ceil(speed);
obj.style.webkitTransform = "translate3d("+matrix+"px,80px,0)";
if (matrix >= 700) {
// clearInterval(go);
var fullBack = setInterval(function(){
speed = matrix/20;
matrix -= Math.ceil(speed)
obj.style.webkitTransform = "translate3d("+matrix+"px,80px,0)";
if (matrix <= 100) {
clearInterval(fullBack);
obj.style.webkitTransform = "translate3d("+100+"px,80px,0)";
}
},20)
}
},20);
}
</script>
</div>
<div class="area">
<button type="button" class="play2">Play</button>
<div class="obj2" style="position:absolute;top:80px;left:100px">
</div>
<script>
var playBtn2 = document.querySelector(".play2");
var obj2 = document.querySelector(".obj2");
var matrix2 = parseInt(obj2.style.left);
playBtn2.onclick = function() {
var speed2;
var go2 = setInterval(function(){
speed2 = matrix2/20;
matrix2 += Math.ceil(speed2)
obj2.style.left = matrix2 + "px";
if (matrix2 >= 700) {
//clearInterval(go2);
var fullBack2 = setInterval(function(){
speed2 = matrix2/20;
matrix2 -= Math.ceil(speed2)
obj2.style.left = matrix2 + "px";
if (matrix2 <= 100) {
clearInterval(fullBack2)
obj2.style.left = 100 + "px";
}
},20)
}
},20);
}
</script>
</div>
<div class="area">
<button type="button" class="play3">Play</button>
<div class="obj3"></div>
<script>
var playBtn3 = document.querySelector(".play3");
var obj3 = document.querySelector(".obj3");
playBtn3.onclick = function() {
obj3.setAttribute("class","obj3 go")
}
</script>
</div>
<div class="area">
<button type="button" class="play4">Play</button>
<div class="obj4"></div>
<script>
var playBtn4 = document.querySelector(".play4");
var obj4 = document.querySelector(".obj4");
playBtn4.onclick = function() {
var handle = 0;
var speed4;
renderLoop();
function renderLoop() {
var matrix4 = new WebKitCSSMatrix(window.getComputedStyle(obj4,null).webkitTransform).m41;
speed4 = matrix4/20;
matrix4 += Math.ceil(speed4);
obj4.style["-webkit-transform"] = "translate3d("+ matrix4 +"px,80px,0)";
handle = window.requestAnimationFrame(renderLoop);
if (matrix4 >= 700) {
//window.cancelAnimationFrame(handle);
handle = null;
renderLoop2()
function renderLoop2() {
matrix4 -= Math.ceil(speed4);
obj4.style["-webkit-transform"] = "translate3d("+ matrix4 +"px,80px,0)";
handle = window.requestAnimationFrame(renderLoop2);
if(matrix4 <= 100) {
window.cancelAnimationFrame(handle)
handle = null
obj4.style["-webkit-transform"] = "translate3d(100px,80px,0)";
}
// console.log(matrix4)
}
}
}
}
</script>
</div>
<div class="area">
</div>
</body>
</html>