【问题标题】:Jitter on chrome css animationschrome css动画上的抖动
【发布时间】:2013-11-13 05:58:48
【问题描述】:

通过使用具有相同背景图像 [svg] 的两个居中 div 并为其宽度和背景位置设置动画,尝试制作一个从中心淡入图像的 css 动画。问题是,在 chrome 上,有一个可怕的抖动问题(可能是由于 chrome 循环播放动画步骤,而不是同时执行它们?)

这是 jsfiddle:http://jsfiddle.net/evankford/s2uRV/4/,您可以在其中看到左侧的抖动问题(同时具有宽度动画和背景位置动画)。

相关代码(对于它所在网站的一些剩余内容,抱歉)

HTML:

    <div class="underheader-wrapper uhw-title">
       <div class="underheader uhleft undertitle">&nbsp;</div>
       <div class="underheader uhright undertitle">&nbsp;</div>
    </div>

还有 CSS:

   .undertitle {
-webkit-backface-visibility: hidden;
 -webkit-transform: translateZ(0);
background-image:url(http://cereusbright.com/newsite/presskit/images/underheader.svg);
}

.underheader-wrapper {
position: relative;
margin:  auto;
width:320px;
height:100px;
}

.underheader {
-webkit-backface-visibility: hidden;
position:absolute;
width: 0px;
height:100px;
opacity: 0;
background-size: 320px 60px;
background-repeat: no-repeat;
-moz-animation-delay: 3s; -webkit-animation-delay:3s;
-moz-animation-duration: 3s; -webkit-animation-duration: 3s;
-moz-animation-name: part1; -webkit-animation-name:part1;
-webkit-animation-fill-mode:forwards;
-moz-animation-fill-mode:forwards}

.uhleft {
background-position: -160px 40px;
right: 160px;
-webkit-backface-visibility: hidden;
-moz-animation-delay: 3s; -webkit-animation-delay:3s;
-moz-animation-duration: 3s; -webkit-animation-duration: 3s;
-moz-animation-name: part2; -webkit-animation-name:part2;
-webkit-animation-fill-mode:forwards; 
-moz-animation-fill-mode:forwards}

.uhright {
background-position: -160px 40px;
left: 160px;}

@-webkit-keyframes part1 {
from {
    width: 0px;
    opacity: 0;
}
to {
    width: 160px;
    opacity: 1;
}}

@-webkit-keyframes part2 {
from {
    background-position:-160px 40px;
    width: 0px;

    opacity: 0;
}
to {
    width: 160px;
    background-position: 0px 40px;
    opacity: 1;
}}

@-moz-keyframes part1 {
from {
    width: 0px;
    opacity: 0;
}
to {
    width: 160px;
    opacity: 1;
}}

@-moz-keyframes part2 {
from {
    background-position:-160px 40px;
    width: 0px;
    opacity: 0;
}
to {
    background-position: 0px 40px;
    width: 160px;
    opacity: 1;
}}

我是否被这种抖动困扰?我已经做了一个 JQuery 版本,发现有人说 CSS 更干净/更流畅,但抖动仍然存在。

【问题讨论】:

    标签: html css animation


    【解决方案1】:

    好的,没有找到使用双 div 来实现此目标的方法。相反,我做了这样的事情。

    <div class="outer">
         <div class="middle">
                <div class"inner">
                 &nbsp
                </div>
          </div>
    </div>
    

    然后设置样式

    .outer {
    position: relative;
    width:321px;
    height:100px;
    padding: 15px;
    } 
    
    .middle {
    text-align: center;
    position: absolute;
    left: 160px;
    margin:auto;
    background-image:url(images/underheader.svg);
    background-position:center center;
    background-size: 320px 70px;
    background-repeat: no-repeat;
    /*all the animation stuff */
     }
    
    .inner {
    position: relative;
    display: inline-block;
    width: 0px;
    height: 100px;
    /* all the animation stuff */
     }
    

    然后,我将中间 div 从 left:160px 动画到 left: 0px 并将内部 div 从 width: 0px 动画到 width: 320px. 我使用了 CSS 动画,尽管它可以通过 jquery 或 CSS 过渡轻松完成。

    【讨论】:

      【解决方案2】:

      您在 Chrome 上看到的延迟由 -webkit-animation-delay:3s; 给出。将其更改为-webkit-animation-delay:0s;,您会看到它会立即开始淡入。

      【讨论】:

      • 即使改成-webkit-animation-delay:0s;还是能看到
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      • 2011-09-21
      • 2017-08-03
      • 1970-01-01
      • 2014-01-21
      • 2013-03-01
      相关资源
      最近更新 更多