0
我有兩個故意重疊的畫布繪製落在另一個畫布上的球。我想在頁面上的這兩個重疊部分之下放置第三個畫布,而沒有任何重疊。當保存重疊畫布的div元素具有相對位置時,它不會阻止其他元素與其重疊。據我瞭解,該div必須相對定位,以便它內部的畫布可以絕對定位並重疊。將畫布放置在重疊畫布下方
這裏是我的HTML:
<div id="box" style="position: relative;"></div>
<div id="countdiv"></div>
這裏是JavaScript:
boxCanvas = document.createElement("canvas");
// the margins on the page are 3%
boxCanvas.width = window.innerWidth - (window.innerWidth * .06);
boxCanvas.height = document.getElementById("height").value;
boxCanvas.style = "border: 1px solid #808080; position: absolute; left: 0; top: 0; z-index: 0";
document.getElementById("box").appendChild(boxCanvas);
// second canvas for drawing balls falling
ballCanvas = document.createElement("canvas");
ballCanvas.width = boxCanvas.width;
ballCanvas.height = boxCanvas.height;
ballCanvas.style = "border: 1px solid #808080; position: absolute; left: 0; top: 0; z-index: 1";
document.getElementById("box").appendChild(ballCanvas);
這裏是JavaScript的第三帆布:
countCanvas = document.createElement("canvas");
countCanvas.width = window.innerWidth - (window.innerWidth * .06);
countCanvas.height = 100;
countCanvas.style = "border: 1px solid #808080;";
document.getElementById("box").appendChild(countCanvas);
countctx = countCanvas.getContext("2d");
ballCanvas.height = boxCanvas.height;
ballCanvas.style = "border: 1px solid #808080; position: absolute; left: 0; top: 0; z-index: 1";
document.getElementById("countdiv").appendChild(ballCanvas);
的問題可以看出當你點擊drawbox()然後「顯示hitcounts」時,你可以使用here。謝謝您的幫助!讓我知道我是否可以提供更多信息。
這正是我是問,謝謝!我很欣賞答案,這正是我期待的!我不知道你可以使用CSS來設置屬性的高度和寬度,以避免重疊。再一次感謝你。 – Langston