问题描述
我想把我作为真正HTML按钮的游戏的按钮,但他们需要在画布内。
I want to make the buttons for the game I'm making as real HTML buttons, but they need to be inside the canvas.
我会如何去
推荐答案
由于具有,它可以包含在 canvas
元素不被支持的情况下显示的 fallback 元素。
Given that the canvas element has a transparent content model, it may contain fallback elements which are displayed in the event that the canvas
element is unsupported. They will not be displayed if the canvas is supported.
您可以将HTML元素相对于画布的位置放置在 父级具有悬停在画布上的按钮。 可以是用于呈现控件列表的适当语义元素,具体取决于上下文:
You can position HTML elements relative to the canvas' parent to have the buttons "hovering" over the canvas. A menu element could be an appropriately semantic element to render a list of controls, depending on the context:
<div id="container">
<canvas id="viewport">
</canvas>
<menu id="controls">
</menu>
</div>
#container
{
height: 400px;
position: relative;
width: 400px;
}
#viewport
{
height: 100%;
width: 100%;
}
#controls
{
bottom: 0;
left: 0;
position: absolute;
width: 100%;
}
这篇关于我可以在画布中放置一个HTML按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!