<tfoot id='cQNhN'></tfoot>

        <legend id='cQNhN'><style id='cQNhN'><dir id='cQNhN'><q id='cQNhN'></q></dir></style></legend>
          <bdo id='cQNhN'></bdo><ul id='cQNhN'></ul>
      1. <small id='cQNhN'></small><noframes id='cQNhN'>

      2. <i id='cQNhN'><tr id='cQNhN'><dt id='cQNhN'><q id='cQNhN'><span id='cQNhN'><b id='cQNhN'><form id='cQNhN'><ins id='cQNhN'></ins><ul id='cQNhN'></ul><sub id='cQNhN'></sub></form><legend id='cQNhN'></legend><bdo id='cQNhN'><pre id='cQNhN'><center id='cQNhN'></center></pre></bdo></b><th id='cQNhN'></th></span></q></dt></tr></i><div id='cQNhN'><tfoot id='cQNhN'></tfoot><dl id='cQNhN'><fieldset id='cQNhN'></fieldset></dl></div>

      3. 调整 HTML5 画布大小以适应窗口

        Resize HTML5 canvas to fit window(调整 HTML5 画布大小以适应窗口)

            <legend id='iZRU6'><style id='iZRU6'><dir id='iZRU6'><q id='iZRU6'></q></dir></style></legend>
            <tfoot id='iZRU6'></tfoot>

              <i id='iZRU6'><tr id='iZRU6'><dt id='iZRU6'><q id='iZRU6'><span id='iZRU6'><b id='iZRU6'><form id='iZRU6'><ins id='iZRU6'></ins><ul id='iZRU6'></ul><sub id='iZRU6'></sub></form><legend id='iZRU6'></legend><bdo id='iZRU6'><pre id='iZRU6'><center id='iZRU6'></center></pre></bdo></b><th id='iZRU6'></th></span></q></dt></tr></i><div id='iZRU6'><tfoot id='iZRU6'></tfoot><dl id='iZRU6'><fieldset id='iZRU6'></fieldset></dl></div>

              <small id='iZRU6'></small><noframes id='iZRU6'>

                • <bdo id='iZRU6'></bdo><ul id='iZRU6'></ul>
                    <tbody id='iZRU6'></tbody>
                  本文介绍了调整 HTML5 画布大小以适应窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何自动缩放 HTML5 <canvas> 元素以适应页面?

                  How can I automatically scale the HTML5 <canvas> element to fit the page?

                  例如,我可以通过将 heightwidth 属性设置为 100% 来使 <div> 进行缩放,但是<canvas> 不会缩放,对吗?

                  For example, I can get a <div> to scale by setting the height and width properties to 100%, but a <canvas> won't scale, will it?

                  推荐答案

                  我相信我已经找到了一个优雅的解决方案:

                  I believe I have found an elegant solution to this:

                  JavaScript

                  /* important! for alignment, you should make things
                   * relative to the canvas' current width/height.
                   */
                  function draw() {
                    var ctx = (a canvas context);
                    ctx.canvas.width  = window.innerWidth;
                    ctx.canvas.height = window.innerHeight;
                    //...drawing code...
                  }
                  

                  CSS

                  html, body {
                    width:  100%;
                    height: 100%;
                    margin: 0;
                  }
                  

                  到目前为止,对我的性能没有任何大的负面影响.

                  Hasn't had any large negative performance impact for me, so far.

                  这篇关于调整 HTML5 画布大小以适应窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)

                    <tfoot id='nQps2'></tfoot>
                  • <small id='nQps2'></small><noframes id='nQps2'>

                    • <legend id='nQps2'><style id='nQps2'><dir id='nQps2'><q id='nQps2'></q></dir></style></legend>
                        <tbody id='nQps2'></tbody>
                        <bdo id='nQps2'></bdo><ul id='nQps2'></ul>

                      • <i id='nQps2'><tr id='nQps2'><dt id='nQps2'><q id='nQps2'><span id='nQps2'><b id='nQps2'><form id='nQps2'><ins id='nQps2'></ins><ul id='nQps2'></ul><sub id='nQps2'></sub></form><legend id='nQps2'></legend><bdo id='nQps2'><pre id='nQps2'><center id='nQps2'></center></pre></bdo></b><th id='nQps2'></th></span></q></dt></tr></i><div id='nQps2'><tfoot id='nQps2'></tfoot><dl id='nQps2'><fieldset id='nQps2'></fieldset></dl></div>