html5 - CSS中translate和position: relative设置的偏移有什么区别?
大家讲道理
大家讲道理 2017-04-17 11:03:55
0
2
1124

position: relative;也是相对自己当前位置。 transform: translate(x,y);也是相对于当前位置偏移吧? 有什么区别呢?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
阿神

From a page layout perspective

transform and position:relative have the same effect.

The difference is that transform can simply act on the position:absolute element, while position:relative; requires additional html


From an animation perspective

There is a big difference when using transform or position to achieve animation effects.

When using transform, the GPU can be involved in the calculation, and the FPS of the animation will be higher.

When using position, the smallest unit of animation change is 1px, and when using transform to participate, it can be smaller (the animation effect is smoother)

Reference materials: Why Moving Elements With Translate() Is Better Than Pos:abs Top/left

by Paul Irish

Summary

  • Position is born for page layout.
  • transform is made for animation.
巴扎黑

The functions are the same. But translate will not cause the browser to redraw or reflow, which is quite nice.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template