Transform is more predictable than zoom across browsers.
Zoom affects positioning differently in different browsers.
example:
position:absolute; left:50px; zoom: 50%;
- IE will not change the
left
value at all.
- Chrome will change the left value to
25px
. Effectively it does do left = left * zoom
. But DevTools Computed Values in DevTools will still display left: 50px
, even though that is effectively not true due to the zoom.
Transform is handled the same way in all browsers (as far as I can tell).
example:
position:absolute; left:50px; transform: scale(0.5)
left
would effectively be set to 25px
in both Chrome and IE. (again, computed values will still not reflect this, it will display left:50px
)
- To avoid changing the
left
value, simply use transform-origin: 0 0
. That will ensure left is still 50px.
Demo: http://jsfiddle.net/4z728fmk/ shows 2 boxes where the small one is zoomed or scaled to 50%. Looks like this:
edit: img updated 2016-06-16 with Firefox (nothing had change in Chrome or IE since last time)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…