2013-11-01 105 views
7

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

这里是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比较干净/平滑,但抖动仍然发生。

回答

1

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

<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 */ 
} 

我则动画从left:160px中期股利left: 0pxwidth: 0pxwidth: 320px.内的div我用CSS动画,但它可以很容易地使用jQuery或完成CSS转换。

0

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

+0

即使改为'-webkit-animation-delay:0s,我仍然可以看到它; – AbdelElrafa