Google Chrome 中的 HTML5 Canvas 及 z-index 問題


當我們對位置固定的 Canvas 應用 z 索引時,它會停止導致 Chrome 正確渲染所有具有 *position:fixed* 的其他元素。僅當 Canvas 大小超過 256X256 畫素時才會出現這種情況。

用固定 div 將 h1 和 Canvas 包裹起來並解決問題 −

<div id = 'fixcontainer'>
   <h1>Test Title</h1>
   <canvas id = "backgroundCanvas" width = "1000" height = "300"></canvas>
</div>

以下為 CSS −

h1{
   position: fixed;
}
body{
   height: 1500px;
}
canvas{
   position: fixed; z-index: -10;
}

更新於:04-Mar-2020

676 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.