查看此JSBIN:http://jsbin.com/hufibisawa/1/edit?css,js,output
启动Chrome:
使用"左"和"宽度"属性在一起它完美地工作,但它不是高效的。原因是translate3d触发HW加速并使用子像素计算,这给出了非常平滑的动画。
这是一个错误吗?它可以解决吗?使用Firefox这很棒!那么也许是Chrome漏洞?
css
#test {
position: absolute;
transition: transform 1s ease-out, width 1s ease-out;
left: 0;
top: 0;
transform: translate3d(0, 0, 0);
width: 300px;
height: 25px;
background-color: red;
}
#test2 {
position: absolute;
transition: transform 1s ease-out, width 1s ease-out;
left: 0;
transform: translate3d(0, 25px, 0);
top: 0;
width: 300px;
height: 25px;
background-color: green;
}
和JS
document.querySelector('#button').addEventListener('click', function () {
var el = document.querySelector('#test');
el.style.width = '150px';
el.style.transform = 'translate3d(0px, 0px, 0)';
var el = document.querySelector('#test2');
el.style.width = '150px';
el.style.transform = 'translate3d(150px, 0px, 0)';
});
document.querySelector('#button2').addEventListener('click', function () {
var el = document.querySelector('#test');
el.style.width = '300px';
el.style.transform = 'translate3d(0px, 0px, 0)';
var el = document.querySelector('#test2');
el.style.width = '300px';
el.style.transform = 'translate3d(0, 25px, 0)';
});