我发现给一个具有position:fixed
属性的画布应用z-index会导致Chrome无法正常渲染所有其他具有position:fixed
属性的元素。但是,只有当画布大小大于256x256像素时才会发生这种情况。
以下是一个示例:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style>
h1 { position: fixed; }
body { height: 2000px; }
canvas { position: fixed; z-index: -10; }
</style>
</head>
<body>
<h1>Test Title</h1>
<canvas id="backgroundCanvas" width="956" height="256"></canvas>
<script>
// draw basic shape
(function() {
var c = document.getElementById("backgroundCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.moveTo(0,100);
ctx.lineTo(0,0);
ctx.lineTo(100,0);
ctx.lineTo(1000,1000);
ctx.fillStyle = "rgb(117, 164, 68)";
ctx.fill();
ctx.closePath();
})();
</script>
</body>
</html>
如果您将此复制到HTML文档中并在Chrome中打开,您应该知道我的意思。
我的问题是,有人知道我如何解决这个问题吗?
position:fixed;
。只有当我调整浏览器大小时,它才会在正确的位置呈现。 - Khior