PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] Why scrollbars appear, when I resize the canvas?

 July 18, 2022     canvas, document-body, javascript     No comments   

Issue

I made a page, where the canvas should fill the window. It works, but for some reason scrollbars appear. I don't know, what is the error.

<!doctype html>
<html>

  <head>
    <title>test</title>
    <meta charset="utf-8" />
    <style type="text/css">
      #canvas {
        background-color: #EEEEEE;
      }
      * {
        margin: 0px;
      }
    </style>
    <script type="text/javascript">
      function getSize() {
        var myWidth = 0, myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
          //Non-IE
          myWidth = window.innerWidth;
          myHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
          //IE 6+ in 'standards compliant mode'
          myWidth = document.documentElement.clientWidth;
          myHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth ||          document.body.clientHeight ) ) {
          //IE 4 compatible
          myWidth = document.body.clientWidth;
          myHeight = document.body.clientHeight;
        }
        return {x:myWidth,y:myHeight};
      }

      window.onload = function () {
        canvas = document.getElementById('canvas');
        var size = getSize();
        canvas.width = size.x;
        canvas.height = size.y;
      };
    </script>
  </head>

  <body>
    <canvas id="canvas" width="200" height="200"></canvas>
  </body>

</html>

Solution

Switching #canvas to a block did the trick for me:

#canvas {
    display: block;
    background-color: #EEEEEE;
}


Answered By - fixlr
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing