position: relative;
也是相对自己当前位置。
transform: translate(x,y);
也是相对于当前位置偏移吧?
有什么区别呢?
阿神2017-04-17 11:05:55
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
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巴扎黑2017-04-17 11:05:55
The functions are the same. But translate will not cause the browser to redraw or reflow, which is quite nice.