Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the location of a canvas element?

Can I change the x and y position of a canvas element in Javascript without using CSS? I cannot seem to find anyone who even asks it on the Internet.

EDIT: Can it be done in HTML?

<html>
<title>Testing</title>
    <canvas id="main" width="200" height="200" style="border:1px solid     #c3c3c3;">
    Error: Browser does not support canvas element.
    </canvas>
    <script type="text/javascript">         
        var main = document.getElementById("main");
        var render = main.getContext("2d");
        main.width = 200;
        main.height = 200;
        main.style.left = 100x;
        main.style.top = 100px;
    </script>
</html>
like image 810
MrDrProfessorTyler Avatar asked Feb 09 '12 23:02

MrDrProfessorTyler


People also ask

How do you move elements in canvas?

Moving elements to a different page To select multiple elements, hold Shift on your keyboard, and click to add other elements to the selection. Drag the elements to the new page thumbnail. You'll then be taken to it. Drag the elements into the canvas and position them on the page.

What are the canvas coordinates?

Canvas Coordinates The canvas is a two-dimensional grid. The coordinate (0, 0) is at the upper-left corner of the canvas. Along the X-axis, values increase towards the right edge of the canvas. Along the Y-axis, values increase towards the bottom edge of the canvas.

How do I set my canvas to the center?

To center canvas in HTML 5, include the canvas tag in div tag. Then we can center align the div tag. By doing so, the canvas is also center aligned.


1 Answers

<html>
<title>Testing</title>
    <canvas id="main" width="200" height="200" style="border:1px solid     #c3c3c3;">
    Error: Browser does not support canvas element.
    </canvas>
    <script type="text/javascript">

        var main = document.getElementById("main");
        var render = main.getContext("2d");
        main.width = 200;
        main.height = 200;
        main.style.left = "100px";
        main.style.top = "100px";
        main.style.position = "absolute";
    </script>
</html>
like image 93
Andrei Schneider Avatar answered Oct 19 '22 22:10

Andrei Schneider