流动电路动画

时间:2015-06-21 20:04:20

标签: css

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>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:2)

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

<强> Fiddle demo

&#13;
&#13;
    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%;
    }
}
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

这样的东西?它会创建一个背景并在悬停时激活位置。您可以在页面加载时轻松应用特殊类。

#circuit {
  width: 80%;
  border: 10px solid navy;
  margin: 25px;
  height: 80%;
  margin-left: auto;
  margin-right: auto;
  
  background: linear-gradient(to right, yellow 50%, blue 50%);
  background-size: 200% 100%;
  background-position:right bottom;
  transition:all 2s ease;
}
html,
body {
  height: 100%;
  margin: 0;
}

#circuit:hover {
  background-position:left bottom;
}
<div id="circuit"></div>

答案 2 :(得分:0)

也许这就是你要找的东西:

pg_dump
#circuit {
  position:relative;
  width: 450px;
  height: 150px;
  margin: 10% auto;
  border:1px solid;
  
  background: linear-gradient(to right, yellow 50%, blue 50%);
  background-size: 200% 100%;
  background-position:right bottom;
  transition:all 2s ease;
 
}
html,
body {
  height: 100%;
  margin: 0;
}

#circuit:hover {
  background-position:left bottom;
}
.inner{
background:white;
position:absolute;
top:15%;
left:5%;
bottom:15%;
right:5%;
 }