Laggy CSS动画

时间:2016-05-25 09:09:46

标签: html css css3 animation css-animations

我正在尝试使用CSS3动画在我的网站上调整一些容器。

这是我的容器:

.new-place-wrapper {
  background: #004682;
  display: inline-block;
  margin-top: 70px;
  animation-name: newplace;
  animation-duration: 1s;
  animation-fill-mode: forwards;
  animation-delay: 3s;
  animation-timing-function: linear;
  max-height: 0px;
  padding: 0px 20px;
  overflow: hidden;
  position: relative;
  z-index: 8888;
}

@keyframes newplace {
  0% {
    max-height: 0px;
    padding: 0px 20px;
  }
  100% {
    max-height: 9999px;
    padding: 20px 20px;
  }
}
<div class="new-place-wrapper" data-equalizer>
  <div class="new-place-close"><i class="fa fa-times"></i></div>
  <div class="inner-place-left" data-equalizer-watch>
    <span>Wir sind umgezogen!</span>
    Ab sofort finden Sie uns hier:
    <address>
      <strong>Company</strong><br>
      STREET 123<br>
      CITY<br><br>
      PHONE
    </address>
  </div>
  <div class="inner-place-right" data-equalizer-watch>
    <a class="button radius" href="#">VCF-Karte</a>
  </div>
</div>

基本上动画效果很好,但开头有一个奇怪的滞后。首先容器变得更加颤抖。过了一会儿,动画很顺利。

Check it out over here!(等待5秒!)

2 个答案:

答案 0 :(得分:3)

我已经阅读了有关转换的内容,主要结论是,您应该避免转换宽度/高度,左/右/上/下,而是使用转换属性。

这些答案可能会对您有所帮助:

Why transitions for some CSS properties are slow and none fluent

How to smoothly animate height in CSS or Javascript on mobile devices

答案 1 :(得分:1)

降低最大高度以更好地查看动画。

.new-place-wrapper {
  background: #004682;
  display: inline-block;
  margin-top: 70px;
  animation-name: newplace;
  animation-duration: 1s;
  animation-fill-mode: forwards;
  animation-delay: 3s;
  animation-timing-function: linear;
  max-height: 0px;
  padding:  0 20px;
  overflow: hidden;
  position: relative;
  z-index: 8888;
}

@keyframes newplace {
  0% {
    max-height: 0px;
  }
  100% {
    max-height: 309px;
    padding-top: 20px;
    padding-bottom:20px;
  }
}
<div class="new-place-wrapper" data-equalizer>
  <div class="new-place-close"><i class="fa fa-times"></i></div>
  <div class="inner-place-left" data-equalizer-watch>
    <span>Wir sind umgezogen!</span>
    Ab sofort finden Sie uns hier:
    <address>
      <strong>Company</strong><br>
      STREET 123<br>
      CITY<br><br>
      PHONE
    </address>
  </div>
  <div class="inner-place-right" data-equalizer-watch>
    <a class="button radius" href="#">VCF-Karte</a>
  </div>
</div>