Jump to content

[Solved] Canvas on whole window and behind all html elements


8Observer8
 Share

Recommended Posts

Hello,

Please, help me to set canvas on whole window, behind of all html elements

It works fine:

 

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script src="./libs/pixi.min.js"></script>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #myCanvas {
            margin: 0;
            padding: 0;
            position: absolute;
            touch-action: none;
            width: 100%;
            height: 100%;
            border: 1px dashed;
        }
    </style>
</head>
<body>
    <canvas id="myCanvas" width="256" height="256"></canvas>

    <input type="button" value="button 1">
    <input type="button" value="button 2">
    <h1>Hello</h1>
</body>
</html>

But it doesn't work how is above, because the dashed line doesn't cover whole window (doesn't include buttons)

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script src="./libs/pixi.min.js"></script>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #myCanvas {
            margin: 0;
            padding: 0;
            position: absolute;
            touch-action: none;
            width: 100%;
            height: 100%;
            border: 1px dashed;
        }
    </style>
</head>
<body>
    <canvas id="myCanvas" width="256" height="256"></canvas>

    <input type="button" value="button 1">
    <input type="button" value="button 2">
    <h1>Hello</h1>

    <script>
        var myView = document.getElementById('myCanvas');

        var renderer = PIXI.autoDetectRenderer(
            256, 256,
            { antialias: false, transparent: true, view: myView });

        document.body.appendChild(renderer.view);

        var stage = new PIXI.Container();

        renderer.render(stage);
    </script>
</body>
</html>

 

Link to comment
Share on other sites

I am not sure but I think you wanted to write :

<body>
    <input type="button" value="button 1">
    <input type="button" value="button 2">
    <h1>Hello</h1>
    <canvas id="myCanvas" width="256" height="256"></canvas>
</body>

Use this css:

        #myCanvas {
            margin: 0;
            padding: 0;
            position: fixed;
            touch-action: none;
            width: calc(100% - 2px); /* for borders */
            height: calc(100% - 2px); /* for borders */
            border: 1px dashed;
            top:0;
            left:0;
        }

 

Link to comment
Share on other sites

Thanks! This is a solution of first part of my question:

        #myCanvas {
            /*...*/
            top: 0;
            left: 0;
        }

The second part. I want to place <canvas> behind of all html elements. I want to place buttons over the canvas and I want to use canvas like background of my page. Now if I set for renderer the transparent to false I cannot see the buttons.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...