-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIFE_day20_Practice.html
200 lines (184 loc) · 5.76 KB
/
IFE_day20_Practice.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>IFE ECMAScript</title>
<style>
select {
display: none;
}
.palette {
margin-top: 20px;
padding: 0;
list-style: none;
width: 200px;
height: 100px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.palette li {
width: 40px;
height: 40px;
border: 1px solid #000;
cursor: pointer;
}
#donghua {
width: 480px;
height: 480px;
background-image: url('./images/erik_ce204002.jpg');
background-repeat: no-repeat;
background-position: 0;
}
#img {
position: fixed;
right: 30%;
top: 15%;
}
</style>
</head>
<body>
<!-- 编码 一 -->
<input id="inp1" type="text" value="" onkeydown="keyD(event)"/>
<button id="btn1" type="submit" >提交</button>
<hr>
<!-- 编码 二 -->
<label>
<input id="school" name="status" type="radio">
School
</label>
<label>
<input id="company" name="status" type="radio">
Company
</label>
<select id="school-select">
<option>北京邮电大学</option>
<option>黑龙江大学</option>
<option>华中科技大学</option>
</select>
<select id="company-select">
<option>百度</option>
<option>爱奇艺</option>
</select>
<!-- 编码 三 -->
<ul class="palette" >
<li style="background-color:crimson"></li>
<li style="background-color:bisque"></li>
<li style="background-color:blueviolet"></li>
<li style="background-color:coral"></li>
<li style="background-color:chartreuse"></li>
<li style="background-color:darkolivegreen"></li>
<li style="background-color:cyan"></li>
<li style="background-color:#194738"></li>
</ul>
<p class="color-picker"></p>
<!-- 编码 四 -->
<div id="fade-obj" style="width:200px;height:200px;background:#000"></div>
<button id="fade-btn">淡出</button>
<!-- 编码 五 -->
<div id='img'>
<div id="donghua"></div>
<button id="begin" style="background: chartreuse;">动起来</button>
<button id="stop" style="background: crimson;">STOP</button>
</div>
<script>
//编码一
var oInp = document.getElementById("inp1");
var oBtn = document.getElementById('btn1');
function keyD(e){
var keynum;
keynum = window.event ? e.keyCode: e.which;
if(keynum==13){
alert(oInp.value);
}
else if(keynum==27){
oInp.value = "";
}
}
oBtn.onclick = function (){
alert(oInp.value);
}
//编码二
var oSch = document.getElementById('school');
var oCom = document.getElementById('company');
var oSchSel = document.getElementById("school-select");
var oComSel = document.getElementById('company-select');
oSch.onclick = function(){
oSchSel.style.display = "block";
oComSel.style.display = "none";
}
oCom.onclick = function(){
oSchSel.style.cssText = "display: none";
oComSel.style.cssText = "display: block";
}
//编码三
var aLi = document.querySelector(".palette").querySelectorAll('li');
var p = document.querySelector('.color-picker');
for(var item of aLi){
item.onclick = function (e){
var c = e.target.style.backgroundColor;
p.innerHTML = c;
p.style.color = c;
}
}
//编码四 淡出淡入
var oDiv = document.getElementById('fade-obj');
var oBtn2 = document.getElementById('fade-btn');
var opc = 1;
function changeOpc(){
oDiv.style.opacity = opc;
opc -= 0.1;
if(opc >0){
setTimeout(changeOpc, 100);
oBtn2.disabled = "disabled";
}
else{
oBtn2.innerHTML = "淡入";
oBtn2.disabled = "";
}
}
function changeOpc2(){
oDiv.style.opacity = opc;
opc += 0.1;
if(opc < 1){
setTimeout(changeOpc2, 100);
oBtn2.disabled = "disabled";
}
else{
oBtn2.innerHTML = "淡出";
oBtn2.disabled = "";
}
}
oBtn2.onclick = function(){
if(opc>=1){
setTimeout(changeOpc, 100);
}
else if(opc<=0){
setTimeout(changeOpc2, 100);
}
}
//编码五 一帧动画
var oDonghua = document.getElementById('donghua');
var oBtnBegin = document.getElementById('begin');
var oBtnStop = document.querySelector('#stop');
var topValue = 0;
var timer1;
function changeTop () {
oDonghua.style.backgroundPosition = '0' + '' + topValue+'px';
topValue -= 480;
if(topValue <= -8160) {
topValue = 0;
}
timer1 = setTimeout(changeTop, 100)
}
oBtnBegin.onclick = function(){
// 先清除定时器 否则每次重复点击将加快速度
clearTimeout(timer1);
timer1 = setTimeout(changeTop, 100);
}
oBtnStop.onclick = function(){
clearTimeout(timer1);
}
</script>
</body>
</html>