Android 2.2 上出现 CSS3 动画闪烁问题 (同时使用 webkit-transform:translate(..) scale(..))

10

我在Android上对CSS3动画(使用webkit-transition进行转换)进行了一些研究。

CSS3动画仍然是Webkit中的实验性功能。如果您尝试同时进行缩放和平移,您会发现CSS动画中存在一些小问题和/或错误(例如,请参见http://www.youtube.com/watch?v=vZdBVzN1B8Y)。换句话说,在许多版本的Android中,属性-webkit-transform:matrix(...)不能正确工作。同时进行缩放和平移的唯一正确方法是以这个顺序设置"-webkit-transform:scale(...) translate(...)"

我将在本文底部分享我的结果。

正如您所看到的,我已经克服了其中大部分问题。但是,在Android 2.2(Froyo)上的某些转换中仍然存在一些“闪烁”问题。

现在我的问题是:是否有任何方法可以在Android 2.2上同时进行缩放和平移而不会出现闪烁?

我还尝试了-webkit-backface-visibility:hidden;, -webkit-perspective:1000;-webkit-transform:translate3d(..,0)但这些属性会在转换中引入一些故障。您可以在以下视频中看到它: http://www.youtube.com/watch?v=Aplk-m8WRUE 缩放在转换停止后被取消。

有没有其他解决闪烁的方法? 有什么想法吗?


以下是我在Android(1.5 <= ver <= 2.2)上关于CSS3过渡效果的结果。 它同时使用缩放和平移来控制蓝色框的动画。
<html>
<head>
 <title>css3test</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <meta name="viewport" content="width=device-width">
</head>
<body>
<div id='log'></div>
<div id='box' style="background-color: blue; width:100; height:100;"></div>
<script language='JavaScript'>
function mesg(str) {
  document.getElementById('log').innerHTML = str;
}
var e = document.getElementById('box');
e.style['-webkit-transition-property'] = '-webkit-transform';
e.style['-webkit-transform-origin'] = "0 0";
e.style['-webkit-transition-duration'] = '350ms';
e.style['-webkit-transition-timing-function'] = 'linear';

// These properties will suppress flicker, but spoiles scaling on Android 2.2 ...
// see http://www.youtube.com/watch?v=Aplk-m8WRUE
e.style['-webkit-backface-visibility'] = 'hidden'; 
e.style['-webkit-perspective'] = '1000';

var b = 0;
function doAnim() {
  var trans;
  switch(b){
  case 0: // step 0. translate and scale at the same time
    // 1) matrix
    // On Android 1.5, we get no translation, but the box is only enlarged. Broken.
    // On Android 2.2, the transition does not occur but the box moves instantly.
    //trans = 'matrix(2,0,0,2,100,100)';
    // 2) scale first, then translate
    // On Androi2.2, there's some glitches.
    //trans = 'scale(2,2) translate(50px,50px)'; 
    // 3) tranlate first, then scale -- CORRECT 
    trans = 'translate(100px,100px) scale(2,2)';
    break;
  case 1: // step 1. translate
    // 1) matrix 
    //trans = 'matrix(1,0,0,1,35,35)';
    // 2) translate only -- will spoil transition -- 
    // On Android 1.5, the transition corrupts and the box repeatedly moves in a wrong direction. Bug?
    // see http://www.youtube.com/watch?v=vZdBVzN1B8Y
    //trans = 'translate(35px,35px)';
    // 3) tranlate first, then scale with (1,1) -- CORRECT 
    trans = 'translate(35px,35px) scale(1,1)';
    break;
  case 2: // step 2. scaling
    // 1) matrix -- nope.
    //trans = 'matrix(1.4,0,0,1.4,0,0)';
    // 2) scale only -- will spoil transition --
    //trans = 'scale(1.4,1.4)';
    // 3) tranlate with (0px,0ox), then scale -- CORRECT 
    trans = 'translate(0px,0px) scale(1.4,1.4)';
    break;
  case 3: // step 3. again, translate and scale at the same time
    // 1) matrix -- nope.
    //trans = 'matrix(1.2,0,0,1.2,100,100)';
    // 2) scale then translate -- will spoil transition --
    //trans = 'scale(1.2,1.2) translate(83.33px,83.33px)';
    // 3) tranlate first, then scale -- CORRECT 
    trans = 'translate(100px,100px) scale(1.2,1.2)';
    break;
  }
  e.style['-webkit-transform'] = trans;
  mesg('move '+b+'<br/>transform:'+trans);

  b=(b+1)%4;
}
var isAndroid = (new RegExp("android","gi")).test(navigator.appVersion);
if(isAndroid) {
  e.addEventListener('touchstart', doAnim, false);
} else {
  e.addEventListener('mousedown', doAnim, false);
}
document.addEventListener('touchmove', function(e){ e.preventDefault(); }, false);
</script>
</body>
</html>
3个回答

11

一年过去了,这个漏洞仍然存在。很糟糕...我感觉有些安卓用户已经习惯了某些故障。 - courtsimas

2
在大多数情况下,闪烁是由正在被动画化的嵌套元素引起的。减少嵌套元素的数量可能在某些情况下很困难,但大多数情况下这会有所帮助。

我知道,实际上。所以在上面的例子中,元素并没有嵌套。无论如何,感谢您的回复! - Keigo Imai

0
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;

在父元素上进行操作可能会有帮助,具体取决于你正在做什么。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接