1

キャンバスがウィンドウを埋めるページを作成しました。動作しますが、何らかの理由でスクロールバーが表示されます。私は知りません、エラーは何ですか。

<!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>
4

2 に答える 2

3

#canvasをブロックに切り替えると、うまくいきました。

#canvas {
    display: block;
    background-color: #EEEEEE;
}
于 2012-02-12T21:33:22.220 に答える
1

CSS に問題がある可能性があります。

「すべての要素」を一番上に移動し、安全のためにキャンバスを絶対位置に配置しました。

これがうまくいくかどうか教えてください:

<style type="text/css">
          * {
              margin: 0px;
              padding:0px;
          }
          #canvas {
              position:absolute;
              left:0px;
              top:0px;
              background-color: #EEEEEE;
          }

</style>
于 2012-02-12T21:02:30.000 に答える