gpt4 book ai didi

javascript - 如何隐藏 Canvas 或任何其他对象?

转载 作者:行者123 更新时间:2023-11-28 16:52:09 28 4
gpt4 key购买 nike

所以我有一个主 Canvas ,上面有三个 Canvas 。和一段文字。

<canvas id="Background" width="350" height="300"
style="border:6px solid black; position: absolute; left: 10px; top: 10px;">
</canvas>

<canvas id="Canvas1" width="150" height="100"
style="border:6px solid blue; position: absolute; left: 33px; top: 20px;">
</canvas>

<canvas id="Canvas1" width="50" height="50"
style="border:6px solid yellow; position: absolute; left: 33px; top: 200px;">
</canvas>

<canvas id="Canvas1" width="150" height="100"
style="border:6px solid blue; position: absolute; left: 33px; top: 20px;">
</canvas>

<canvas id="Canvas1" width="150" height="100"
style="border:6px solid blue; position: absolute; left: 243px; top: 20px;">
</canvas>

</div>
<div style="position: absolute; left: 70px; top: 50px;">
<p> example </p>
</div>

稍后我会添加onclick事件,当我单击时,我希望文本和其中一张 Canvas 消失。基本上我想知道如何在这段代码中显示/隐藏元素。谢谢!

最佳答案

使用display: nonevisibility: hide。不同之处在于 display: none 会从 View 中完全删除该元素,而 visibility: hide 会保留该元素原本所在的空白空间。哪个合适取决于您的用例。

JS 看起来大致类似于 document.getElementById("Canvas1").style.display = "none";

关于javascript - 如何隐藏 Canvas 或任何其他对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59780546/

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