gpt4 book ai didi

css - 流动电路动画

转载 作者:太空宇宙 更新时间:2023-11-04 03:03:07 25 4
gpt4 key购买 nike

enter image description here

我的网站有一个只有边距的 div,当页面加载时,我想要一个电路效果(我让电池重叠在 div 上)所以从正极开始,电路的颜色变为黄色,然后黄色继续去负极端子。这对 CSS 是否可行?我不完全确定 CSS 的强大功能。

这是我的 div 标签的代码。

#circuit {
width: 80%;
border: 10px solid navy;
margin: 25px;
height: 80%;
margin-left: auto;
margin-right: auto;
}
html,
body {
height: 100%;
margin: 0;
}
<div id="circuit"></div>

最佳答案

一系列关键帧动画可以完成这项工作。您需要修改持续时间和累积延迟以获得您想要的速度。

Fiddle demo

    html, body {
height: 100%;
padding: 0;
margin: 0;
}
* {
box-sizing: border-box;
}
.circuit-outer {
position: relative;
width: 80vw;
height: 80vh;
margin: 5% 10% 0;
padding: 3px;
background: #eee;
border: 1px solid #ddd;
overflow: hidden;
}
.circuit-inner {
position: absolute;
top: 3px;
bottom: 3px;
left: 3px;
right: 3px;
background: #fff;
border: 1px solid #ddd;
}
.current {
background: orange;
position: absolute;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: linear;
-webkit-animation-fill-mode: forwards;
animation-iteration-count: 1;
animation-timing-function: linear;
animation-fill-mode: forwards;
}
.current.bottom-left {
bottom: 0;
right: 80%;
width: 20%;
height: 3px;
-webkit-animation-name: zap1;
-webkit-animation-duration: .2s;
animation-name: zap1;
animation-duration: .2s;
}
.current.left {
bottom: 0;
left: 0;
width: 3px;
height: 0;
-webkit-animation-name: zap2;
-webkit-animation-delay: .2s;
-webkit-animation-duration: .5s;
animation-name: zap2;
animation-delay: .2s;
animation-duration: .5s;
}
.current.top {
top: 0;
width: 0;
height: 3px;
-webkit-animation-name: zap3;
-webkit-animation-delay: .7s;
-webkit-animation-duration: 1s;
animation-name: zap3;
animation-delay: .7s;
animation-duration: 1s;
}
.current.right {
top: 0;
right: 0;
width: 3px;
height: 0;
-webkit-animation-name: zap2;
-webkit-animation-delay: 1.7s;
-webkit-animation-duration: .5s;
animation-name: zap2;
animation-delay: 1.7s;
animation-duration: .5s;
}
.current.bottom-right {
bottom: 0;
right: 0;
width: 0%;
height: 3px;
-webkit-animation-name: zap4;
-webkit-animation-delay: 2.2s;
-webkit-animation-duration: .8s;
animation-name: zap4;
animation-delay: 2.2s;
animation-duration: .8s;
}
@-webkit-keyframes zap1 {
0% {
width: 0;
}
100% {
width: 20%;
}
}
@keyframes zap1 {
0% {
width: 0;
}
100% {
width: 20%;
}
}
@-webkit-keyframes zap2 {
0% {
height: 0;
}
100% {
height: 100%;
}
}
@keyframes zap2 {
0% {
height: 0;
}
100% {
height: 100%;
}
}
@-webkit-keyframes zap3 {
0% {
width: 0;
}
100% {
width: 100%;
}
}
@keyframes zap3 {
0% {
width: 0;
}
100% {
width: 100%;
}
}
@-webkit-keyframes zap4 {
0% {
width: 0;
}
100% {
width: 80%;
}
}
@keyframes zap4 {
0% {
width: 0;
}
100% {
width: 80%;
}
}
<div class="circuit-outer">
<div class="current bottom-left"></div>
<div class="current left"></div>
<div class="current top"></div>
<div class="current right"></div>
<div class="current bottom-right"></div>
<div class="circuit-inner"></div>
</div>

关于css - 流动电路动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30968795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com