-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
220 lines (181 loc) · 5.69 KB
/
index.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style type="text/css">
body{
background-color:#ccc;
padding: 20px;
}
.outer {
position:relative;
display:block;
width: 200px;
height:200px;
background-image:-webkit-linear-gradient(#999,#eee);
border-radius:100px;
padding:5px
}
.inner {
position: absolute;
z-index: 9;
display:block;
width: 140px;
height:140px;
background-color: #F0F3F6;
border-radius: 70px;
margin: 30px;
box-shadow: 0px 2px 3px #333;
}
#text {
display:block;
width: 100%;
text-align: center;
line-height: 140px;
font-family: Helvetica;
font-size: 40px;
color: #4B4F58;
}
.circle {
position: absolute;
top: 0;
left:0;
margin: 5px;
z-index: 1;
display: block;
float: left;
width: 200px;
height: 200px;
border-radius: 100px;
background-image: -webkit-radial-gradient(circle, #fff 60px, #BFC8D0 85px, #4B4F58 100px);
}
.start_mask {
display: block;
width: 100px;
height: 100px;
background-image: -webkit-linear-gradient(right, transparent 95px, rgba(65,157,34,0.2) 100px, transparent 100px);
position: absolute;
top:5px;
left:105px;
z-index: 10;
background-size: 100px 30px;
background-repeat: no-repeat;
opacity:0;
}
.end_mask {
display: block;
width: 100px;
height: 100px;
background-image: -webkit-linear-gradient(left, transparent 95px, rgba(65, 157, 34, 0.2) 100px);
position: relative;
z-index: 10;
background-size: 100px 30px;
background-repeat: no-repeat;
-webkit-transform-origin: right bottom;
opacity:0;
-webkit-transition-timing-function: linear;
}
/* for right 左透明,右填充 */
.mask1 {
position: absolute;
top: 0;
left:0;
margin: 5px;
z-index:2;
display:block;
width:200px;
height:200px;
-webkit-mask-image: -webkit-linear-gradient(left, transparent 100px, #000 100px);
}
/* for left 左填充,右透明*/
.mask2 {
position:absolute;
top:0;
left:0;
margin: 5px;
z-index:2;
display:block;
width:200px;
height:200px;
-webkit-mask-image: -webkit-linear-gradient(left, #000 100px, transparent 100px);
}
.prog {
display: block;
float: left;
width: 200px;
height: 200px;
border-radius: 100px;
background-image: -webkit-radial-gradient(circle, #fff 60px, #64CB39 80px, #21830D 96px);
-webkit-transition-timing-function: linear;
}
/* 右图像,左裁剪 */
.mask1 .prog {
-webkit-mask-image: -webkit-linear-gradient(left, #000 100px, transparent 100px);
}
/* 右裁剪 */
.mask2 .prog {
-webkit-mask-image: -webkit-linear-gradient(left, transparent 100px, #000 100px);
}
</style>
<script type="text/javascript">//<![CDATA[
var sec = 1;
function progress(num) {
if(typeof num == "undefined") {var num = document.getElementsByName("prog")[0].value;}
sec = document.getElementsByName("speed")[0].value / 100;
var right = document.querySelector('.mask1 .prog'),
left = document.querySelector('.mask2 .prog'),
startMask = document.getElementsByClassName('start_mask')[0],
endMask = document.getElementsByClassName('end_mask')[0],
text = document.getElementById('text');
ang = 360 * ( num / 100 );
console.log(ang, ang - 180);
startMask.style.cssText = "opacity:1";
var i = 0,
m = setInterval(function(){if(i >= num) clearInterval(m);text.textContent = (i++)+'%';}, sec*1000/num);
if(num > 0 && num <= 50){
right.style.cssText = "-webkit-transition-duration:"+sec+"s; -webkit-transform:rotate(" + ang + "deg)";
}
else if(num > 50 && num <= 100) {
var rightTime = 50 * sec / num,
leftTime = (num-50)* sec/num;
right.style.cssText = "-webkit-transition-duration:"+rightTime+"s; -webkit-transform:rotate(180deg)";
left.style.cssText = "-webkit-transition-delay:"+rightTime+"s; -webkit-transition-duration:"+leftTime+"s; -webkit-transform:rotate(" + (ang-180) + "deg)";
}
endMask.style.cssText = "-webkit-transition-duration:"+sec+"s; opacity:1; -webkit-transform:rotate(" + ang + "deg)";
}
function reset(){
var right = document.querySelector('.mask1 .prog'),
left = document.querySelector('.mask2 .prog'),
startMask = document.getElementsByClassName('start_mask')[0],
endMask = document.getElementsByClassName('end_mask')[0];
right.style.cssText = left.style.cssText = startMask.style.cssText = endMask.style.cssText = "";
document.getElementById('text').textContent = "0%";
}
//]]>
</script>
</head>
<body>
<!-- 只有 Chrome / Safari 等 Webkit 核心的浏览器才能运行
http://dribbble.com/shots/629733-App-UI-elements
-->
<span class="outer" onclick="progress(80)">
<span class="inner">
<span id="text">0%</span>
</span>
<span class="end_mask" style=""></span>
<span class="start_mask" style=""></span>
<span class="mask1">
<span class="prog" style=""></span>
</span>
<span class="mask2">
<span class="prog" style=""></span>
</span>
<span class="circle">
</span>
</span>
<p>Speed: <input name="speed" type="range" min="1" max="100" value="80"><br>
Progress: <input name="prog" type="range" min="1" max="100" value="80">
</p>
<p style="clear:both"><button onclick="reset()">Reset</button> <button onclick="progress()">Run</button></p>
</body>
</html>