慕田峪9158850
2019-02-19 17:19:13
請問元素在執行keyframe動畫的時候, 執行中設置display:none, 那么動畫會暫停, 如何讓他不暫停呢?
3 回答

明月笑刀無情
TA貢獻1828條經驗 獲得超4個贊
display的切換會觸發reflow,而visibility不會。
因為w3c的wiki中寫到,display的none的解釋是
This value causes an element to not appear in the document. It has no
effect on layout.
即display為none的元素會從常規流中刪除。
而visibility的none的解釋則為
The generated box is invisible (fully transparent, nothing is drawn),
but still affects layout. Furthermore, descendants of the element will
be visible if they have 'visibility: visible'.
意思是說當前元素不可見,但是仍然存在于布局中。
以及常見的還有 opacity: 0 和 (width: 0; height: 0; border: 0 none; overflow: hidden;)
這幾種隱藏方法區別題主可以百度下,很多文章有講,這里就不贅述了。
補充下,動畫中實現漸隱一般是用opacity, 因為透明度可以被量化,實現過渡效果。
添加回答
舉報
0/150
提交
取消