如何关闭盒子类动画

Jir*_*rru 6 html css css-animations

盒式与活塞式一起变得生动起来,但我希望它保持在一个位置。我不知道他如何继承这个动画或为什么。我尝试使用(动画:无!重要;),但是没有用。

@keyframes piston {
  0%,
  100% {
    margin-top: 175px
  }
  50% {
    margin-top: 50px
  }
}

@keyframes handle {
  0%,
  100% {
    height: 225px
  }
  50% {
    height: 100px
  }
}

.piston {
  animation: piston 5s linear infinite;
  background-color: black;
  border: 3px solid black;
  width: 150px;
  height: 50px;
  margin-left: -68px
}

.handle {
  animation: handle 5s linear infinite;
  width: 25px;
  height: 225px;
  margin-left: 68px;
  border: 5px black solid;
  background-color: black;
}

.box {
  width: 156px;
  height: 200px;
  border: 3px solid red;
  border-top: none;
  margin-left: 1px;
}
Run Code Online (Sandbox Code Playgroud)
<div class='handle'>
  <div class='piston'></div>
</div>
<div class='box'></div>
Run Code Online (Sandbox Code Playgroud)

Nic*_*ick 4

您可以通过将HTML 中的divwith类放在with类.box之前,并在 CSS 中设置该类来实现此目的。div.handle.boxposition: fixed

您的动画定位稍有偏差,因此我也为您修复了该问题。您可以更改回动画并调整框的高度以使其适合。

@keyframes piston {
  0%,
  100% {
    margin-top: 140px
  }
  50% {
    margin-top: 50px
  }
}

@keyframes handle {
  0%,
  100% {
    height: 175px
  }
  50% {
    height: 100px
  }
}

.piston {
  animation: piston 5s linear infinite;
  background-color: black;
  border: 3px solid black;
  width: 150px;
  height: 50px;
  margin-left: -68px
}

.handle {
  animation: handle 5s linear infinite;
  width: 25px;
  height: 225px;
  margin-left: 68px;
  border: 5px black solid;
  background-color: black;
}

.box {
  width: 156px;
  height: 200px;
  border: 3px solid red;
  border-top: none;
  margin-left: 2px;
  position: fixed;
}
Run Code Online (Sandbox Code Playgroud)
<div class='box'></div>
<div class='handle'>
  <div class='piston'></div>
</div>
Run Code Online (Sandbox Code Playgroud)