Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitade7ac1

Browse files
committed
add 完整的充电效果
1 parent4275569 commitade7ac1

File tree

3 files changed

+87
-26
lines changed

3 files changed

+87
-26
lines changed

‎06.手机电量/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#手机电量
22

33

4-
5-
64
##知识点
75

86
伪元素、元素的旋转 -> 波浪、动画
97

108

11-
129
##效果
1310

11+
![](https://picgo-use-images.oss-cn-shanghai.aliyuncs.com/images/20220907192519.png)
12+
13+
[来源](https://www.bilibili.com/video/BV1eT4y1175d?spm_id_from=333.999.0.0&vd_source=e5d12c1cab2795094fb351bf2e212c4e)
14+
15+
<spanstyle="color:#0000FF">原来的不支持开始充电和停止充电,且部分代码可以优化</span>

‎06.手机电量/index.html‎

Lines changed: 82 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
display: flex;
1717
justify-content: center;
1818
align-items: center;
19+
background-color:rgb(0,0,0);
1920
}
2021

2122
.content {
@@ -36,7 +37,7 @@
3637
margin-bottom:1vw;
3738
background-color: coral;
3839
border-radius:0.5vw;
39-
font-size:0.6vw;
40+
font-size:0.5vw;
4041
}
4142

4243
/* 点击事件 */
@@ -54,7 +55,7 @@
5455
margin-bottom:1vw;
5556
background-color: coral;
5657
border-radius:0.5vw;
57-
font-size:0.6vw;
58+
font-size:0.5vw;
5859
}
5960

6061
/* 点击事件 */
@@ -70,19 +71,6 @@
7071
position: relative;
7172
margin-bottom:1.6vw;
7273
}
73-
/* 上面突出的那一部分 */
74-
.battery::before {
75-
content:"";
76-
position: absolute;
77-
width:2.6vw;
78-
height:1.2vw;
79-
background-color:rgb(0,0,0);
80-
top:-1.2vw;
81-
left:50%;
82-
transform:translate(-50%);
83-
border-top-left-radius:0.5vw;
84-
border-top-right-radius:0.5vw;
85-
}
8674
/* 充的电 */
8775
.batteryNum {
8876
position: absolute;
@@ -96,15 +84,44 @@
9684
);
9785
bottom:0;
9886
left:0;
99-
top:80%;
10087
border-radius:0.5vw;
10188
/* 动画属性 */
102-
animation: charge5s linear infinite;
89+
animation: charge5s linear1 forwards;
90+
}
91+
.water {
92+
position: absolute;
93+
width:5.2vw;
94+
top:0;
95+
left:0;
96+
bottom:0;
97+
border-radius:0.5vw;
98+
z-index:10;
99+
overflow: hidden;
100+
}
101+
.waterOne {
102+
width:20.8vw;
103+
height:20.8vw;
104+
border-radius:40%48%;
105+
background:rgba(255,255,255,1);
106+
left:50%;
107+
position: absolute;
108+
/* 动画属性 */
109+
animation: waterOne5s linear1 forwards;
110+
}
111+
.waterTwo {
112+
width:20.8vw;
113+
height:20.8vw;
114+
border-radius:32%40%;
115+
background:rgba(255,255,255,1);
116+
position: absolute;
117+
left:50%;
118+
/* 动画属性 */
119+
animation: waterTwo5s linear1 forwards;
103120
}
104121
/* 充电的动画 */
105122
@keyframes charge {
106123
0% {
107-
top:80%;
124+
top:100%;
108125
filter:hue-rotate(90deg);
109126
}
110127
50% {
@@ -116,12 +133,41 @@
116133
filter:hue-rotate(0deg);
117134
}
118135
}
136+
/* 水纹动画1 */
137+
@keyframes waterOne {
138+
0% {
139+
transform:translate(-50%)rotate(0deg);
140+
bottom:0;
141+
}
142+
100% {
143+
transform:translate(-50%)rotate(360deg);
144+
bottom:10.4vw;
145+
}
146+
}
147+
/* 水纹动画2 */
148+
@keyframes waterTwo {
149+
0% {
150+
transform:translate(-50%)rotate(0deg);
151+
bottom:0;
152+
}
153+
100% {
154+
transform:translate(-50%)rotate(360deg);
155+
bottom:10.4vw;
156+
}
157+
}
119158
</style>
120159
</head>
121160
<body>
122161
<divclass="content">
123162
<divclass="battery">
163+
<!-- 充的电量 -->
124164
<divclass="batteryNum"></div>
165+
<!-- 水波纹 -->
166+
<divclass="water">
167+
<!-- 因为需要获取节点,所以设置两个元素,使用伪元素写不方便 -->
168+
<divclass="waterOne"></div>
169+
<divclass="waterTwo"></div>
170+
</div>
125171
</div>
126172
<divclass="option">
127173
<divclass="start">开始充电</div>
@@ -130,13 +176,26 @@
130176
</div>
131177
<script>
132178
// 获取相关节点
133-
letbatteryNumDom=document.querySelector(".batteryNum");
134-
console.log(batteryNumDom);
179+
conststartDOM=document.querySelector(".start");
180+
constbatteryNumDOM=document.querySelector(".batteryNum");
181+
conststopDOM=document.querySelector(".stop");
182+
constwaterOne=document.querySelector(".waterOne");
183+
constwaterTwo=document.querySelector(".waterTwo");
184+
batteryNumDOM.style.animationPlayState="paused";
185+
waterOne.style.animationPlayState="paused";
186+
waterTwo.style.animationPlayState="paused";
135187
// 充电事件
136-
batteryNumDom.onclick=function(){
137-
console.log("1111");
138-
};
188+
startDOM.addEventListener("click",()=>{
189+
batteryNumDOM.style.animationPlayState="running";
190+
waterOne.style.animationPlayState="running";
191+
waterTwo.style.animationPlayState="running";
192+
});
139193
// 停止充电事件
194+
stopDOM.addEventListener("click",()=>{
195+
batteryNumDOM.style.animationPlayState="paused";
196+
waterOne.style.animationPlayState="paused";
197+
waterTwo.style.animationPlayState="paused";
198+
});
140199
</script>
141200
</body>
142201
</html>

‎滚轮视差.zip‎

-1.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp