什么时候用 translate() 而不是 absolute 定位,反之亦然?为什么?
Is there any reason you'd want to use translate() instead of absolute positioning, or vice-versa? And why?
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: hard
分类: css
标签: transform, animation, performance, reflow
参考答案摘要
答案 translate() 属于 transform。改变 transform/opacity 通常不会触发 reflow/repaint(更多是合成/compositing),更适合做动画,通常更流畅。 改 top/left 等绝对定位属性往往会触发布局计算(reflow),动画成本更高。 同时 translate 不会改变元素在文档流中“占位”的事实(更像 relative 的视觉移动),而...
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。