简体   繁体   English

如何将div元素放入画布

[英]how can i put the div element in to canvas

i am trying to put the div element in to canvas. 我试图将div元素放到画布上。

My div element has so many images.that div element i want to put it on canvas. 我的div元素有很多images。那个div元素我想放在画布上。

How can i put the div element to canvas? 如何将div元素放到画布上?

here is my code: 这是我的代码:

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;">

    <div class="rating-container">
        <img class="star" src="images/1.png">
        <img class="star" src="images/1.png">
        <img class="star" src="images/1.png">
        <img class="star" src="images/1.png">
        <img class="star" src="images/1.png">
    </div>
</canvas>

i tried this.. But this is not working properly..How can i fix this? 我试过了..但是这不能正常工作..我该如何解决?

As far as I know, you can't. 据我所知,你做不到。 You could probably use css to place the div on top of the canvas. 您可能会使用CSS将div放在画布上。 You can, however, put images in the canvas http://www.w3schools.com/tags/canvas_drawimage.asp 但是,您可以将图像放在画布上http://www.w3schools.com/tags/canvas_drawimage.asp

You can just put the images right into the canvas. 您可以将图像直接放到画布中。 Not sure if this is really what you are wanting but here is how you would do it. 不知道这是否真的是您想要的,但是这就是您要如何做。

var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var img = document.getElementById("myImage");
context.drawImage(img,10,10);

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM