请求一个动画帧来开始 CSS 过渡是否有意义?
例如,Mozilla CSS 转换页面包含指向此jsfiddle 示例的链接:
CSS:
#foo{
border-radius:50px;
width:50px;
height:50px;
background:#c00;
position:absolute;
top:0;
left:0;
-moz-transition: all 1s;
-webkit-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}
JavaScript:
var f = document.getElementById('foo');
document.addEventListener('click', function(ev){
f.style.left = (ev.clientX-25)+'px';
f.style.top = (ev.clientY-25)+'px';
},false);
如下重写这个例子是否有意义?(见这个 jsfiddle)
JavaScript:
var rAF = window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame;
var f = document.getElementById('foo');
document.addEventListener('click', function(ev){
rAF(function() {
f.style.left = (ev.clientX-25)+'px';
f.style.top = (ev.clientY-25)+'px';
});
},false);
感谢您的任何回答。