简体   繁体   English

左vs CSS3动画中的translateX

[英]left vs translateX in CSS3 Animations

I have created this fiddle ; 我制造了这个小提琴 ; The red box animates with CSS left property, and the blue one animates with CSS Transform TranslateX property. 红色框使用CSS left属性设置动画,蓝色框使用CSS Transform TranslateX属性设置动画。

In Chrome 21, Both animations have the same performace, both running smoothly. 在Chrome 21中,两个动画都具有相同的性能,并且都流畅运行。

But in Safari (for Windows), the blue one animates smoothly, but the red one is laggy. 但是在Safari(适用于Windows)中,蓝色的动画效果很流畅,而红色的动画效果很差。 (Seems that the blue one is hardware-accelerated, while the red one not) (似乎蓝色的是硬件加速的,而红色的不是硬件加速的)

The first question is, What is the best choice? 第一个问题是,最佳选择是什么? Which one is better at overall? 总体上哪个更好? (support by more browsers, etc.) (更多浏览器等的支持)

And next, Isn't there any way to Hardware-accelerate animations on left and top CSS properties in Safari? 接下来,是否没有办法在Safari的lefttop CSS属性中对硬件进行动画加速? (Since I want to actually move a div to outside of window, I think using left property is better.) (由于我实际上想将div移到窗口之外,所以我认为使用left属性会更好。)

Translate is there to move objects around without affecting there position in the DOM. 在那里可以平移对象,而不会影响DOM中的位置。 Although it visibly moves to another place on the screen the DOM is not affect. 尽管它显然移到了屏幕上的另一个位置,但DOM不会受到影响。 This is why the performance of the translate function generally is better. 这就是为什么翻译功能的性能通常更好的原因。

Be warned that you will not see the same performance characteristics in every browser. 请注意,您不会在每种浏览器中看到相同的性能特征。

This is a JSPerf overview of the different translate/move functions. 这是JSPerf概述的不同转换/移动功能。 Scroll to the bottom to see the statistics per browser. 滚动到底部以查看每个浏览器的统计信息。

It will most likely change in the future. 将来很可能会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM