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

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

        <legend id='uKyNr'><style id='uKyNr'><dir id='uKyNr'><q id='uKyNr'></q></dir></style></legend>
      1. <tfoot id='uKyNr'></tfoot>
          <bdo id='uKyNr'></bdo><ul id='uKyNr'></ul>
      2. HTML5 画布调整为父级

        HTML5 canvas resize to parent(HTML5 画布调整为父级)
      3. <legend id='v25mW'><style id='v25mW'><dir id='v25mW'><q id='v25mW'></q></dir></style></legend>
          <tbody id='v25mW'></tbody>

                <bdo id='v25mW'></bdo><ul id='v25mW'></ul>

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

                  <i id='v25mW'><tr id='v25mW'><dt id='v25mW'><q id='v25mW'><span id='v25mW'><b id='v25mW'><form id='v25mW'><ins id='v25mW'></ins><ul id='v25mW'></ul><sub id='v25mW'></sub></form><legend id='v25mW'></legend><bdo id='v25mW'><pre id='v25mW'><center id='v25mW'></center></pre></bdo></b><th id='v25mW'></th></span></q></dt></tr></i><div id='v25mW'><tfoot id='v25mW'></tfoot><dl id='v25mW'><fieldset id='v25mW'></fieldset></dl></div>
                1. <tfoot id='v25mW'></tfoot>
                2. 本文介绍了HTML5 画布调整为父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想调整画布元素的大小,以便适合其父元素,无论是 <body> (全屏")还是一些 <div>例如.这是我的尝试:

                  I want to resize the canvas element so that if fits its parent, whether it's <body> ("full-screen") or some <div> for instance. This is my attempt:

                  // called at each frame
                  function update() {
                      var canvasNode = document.getElementById('mycanvas');
                      canvasNode.width = canvasNode.parentNode.clientWidth;
                      canvasNode.height = canvasNode.parentNode.clientHeight;
                  }
                  

                  由于某种原因,画布不会停止增长!也许 client* 不是正确的参数?

                  For some reason, the canvas doesn't stop growing! Maybe client* aren't the right parameters?

                  在此处查看实际代码:http://jsfiddle.net/ARKVD/24/

                  推荐答案

                  最简单的做法是始终将画布保留在自己的 div 中.

                  The easiest thing to do is to always keep the canvas in its own div.

                  这个 div 中唯一存在的就是画布.

                  The only thing that will ever be in this div is the canvas.

                  然后你可以使用 CSS 来调整你想要的 div 的大小.你想要它和身体一样大吗?给 div width: 100%.

                  Then you can use CSS to resize the div however you want. You want it as large as the body? Give the div width: 100%.

                  那么你总是可以正确地做:

                  Then you can always rightfully do:

                  canvas.width = theDiv.clientWidth;
                  canvas.height = theDiv.clientHeight;
                  

                  如果您这样做,您将不必担心当 body 是 div 的直接父级时您当前面临的奇怪问题.

                  If you do this you won't have to worry about the weird issues that you're currently facing when the body is the direct parent of the div.

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

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

                  相关文档推荐

                  How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                  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(我想沿特定路径对对象进行动画处理)
                3. <i id='N64XN'><tr id='N64XN'><dt id='N64XN'><q id='N64XN'><span id='N64XN'><b id='N64XN'><form id='N64XN'><ins id='N64XN'></ins><ul id='N64XN'></ul><sub id='N64XN'></sub></form><legend id='N64XN'></legend><bdo id='N64XN'><pre id='N64XN'><center id='N64XN'></center></pre></bdo></b><th id='N64XN'></th></span></q></dt></tr></i><div id='N64XN'><tfoot id='N64XN'></tfoot><dl id='N64XN'><fieldset id='N64XN'></fieldset></dl></div>

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

                        <tfoot id='N64XN'></tfoot>

                      1. <legend id='N64XN'><style id='N64XN'><dir id='N64XN'><q id='N64XN'></q></dir></style></legend>
                          <bdo id='N64XN'></bdo><ul id='N64XN'></ul>
                            <tbody id='N64XN'></tbody>