gpt4 book ai didi

javascript - 在页面顶部创建 Canvas

转载 作者:行者123 更新时间:2023-12-03 12:08:05 26 4
gpt4 key购买 nike

我遇到的问题是我想在网页顶部创建 Canvas ,但它总是在底部创建。

var canvas = document.createElement('canvas');
canvas.id = "CursorLayer";
canvas.width = 75;
canvas.height = 25;
//canvas.style.zIndex = 8;
canvas.style.position = "absolute";
canvas.style.border = "1px solid";
canvas.style.display = "inline";
canvas.style.backgroundColor = 'rgba(0,0,0,1)';


var body = document.getElementsByTagName("body")[0];
body.appendChild(canvas);

cursorLayer = document.getElementById("CursorLayer");
var ctx = cursorLayer.getContext("2d");


function daily()
{
ctx.fillStyle="#FFFFFF";
ctx.font="20px Hallo Sans Light";
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillText("asdf",1,20);
}
setInterval(daily,1000);

如果您需要查看网页,请在评论中告诉我

最佳答案

您已将其绝对定位..也许您错过了:

canvas.style.top = 0;

关于javascript - 在页面顶部创建 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25093330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com