ForeveHG / Frontend-Daily-Interview

学习,尝试回答一些前端面试题
1 stars 0 forks source link

69. 在页面上隐藏元素的方法 #70

Open ForeveHG opened 3 years ago

ForeveHG commented 3 years ago

在页面上隐藏元素的方法有哪些?并简述出第一种方法的应用场景和优劣势。

题目来自https://github.com/haizlin/fe-interview/issues/8

ForeveHG commented 3 years ago
  1. display:none; 破坏文档流,会造成回流,页面重新渲染
  2. visibility: hidden; 元素还占有隐藏前的位置,只会产生重绘
  3. opacity: 0; 只改变元素的透明度,产生重绘