• <small id='JfNrm'></small><noframes id='JfNrm'>

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

        缩放 HTML5 画布宽度保留 w/h 纵横比

        Scaling HTML5 canvas width preserving w/h aspect ratio(缩放 HTML5 画布宽度保留 w/h 纵横比)
          <tfoot id='0LVFG'></tfoot><legend id='0LVFG'><style id='0LVFG'><dir id='0LVFG'><q id='0LVFG'></q></dir></style></legend>
            <tbody id='0LVFG'></tbody>
        • <i id='0LVFG'><tr id='0LVFG'><dt id='0LVFG'><q id='0LVFG'><span id='0LVFG'><b id='0LVFG'><form id='0LVFG'><ins id='0LVFG'></ins><ul id='0LVFG'></ul><sub id='0LVFG'></sub></form><legend id='0LVFG'></legend><bdo id='0LVFG'><pre id='0LVFG'><center id='0LVFG'></center></pre></bdo></b><th id='0LVFG'></th></span></q></dt></tr></i><div id='0LVFG'><tfoot id='0LVFG'></tfoot><dl id='0LVFG'><fieldset id='0LVFG'></fieldset></dl></div>

                <bdo id='0LVFG'></bdo><ul id='0LVFG'></ul>
              • <small id='0LVFG'></small><noframes id='0LVFG'>

                  本文介绍了缩放 HTML5 画布宽度保留 w/h 纵横比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个尺寸为 979X482px 的画布元素,我想让它拉伸以适应任何给定浏览器窗口的宽度,保持宽度/高度的纵横比为 1 比 1,我希望高度相对缩放到画布的宽度.关于如何使用 javascript/jQuery 执行此操作的任何建议?

                  I have a canvas element with dimensions of 979X482px and I'd like to have it stretch to fit the width of any given browser window, keeping the aspect ratio of width/hight 1 to 1, I want the height to scale relative to width of the canvas. Any suggestions as how to go about doing this with javascript/jQuery?

                  推荐答案

                  首先你将画布的宽度设置为100%

                  First you set the width of canvas to 100%

                  $('#canvas').css('width', '100%');
                  

                  然后根据它的宽度更新它的高度

                  then update its height base on its width

                  $(window).resize(function(){
                     $('#canvas').height($('#canvas').width() / 2.031);
                  });
                  

                  2.031 = 979/482

                  2.031 = 979/482

                  但你不应该像我一样附加到 $(window).resize ......这是一种不好的行为

                  But you should not attach to $(window).resize like me... it's a bad behavior

                  这篇关于缩放 HTML5 画布宽度保留 w/h 纵横比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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(我想沿特定路径对对象进行动画处理)

                    <tbody id='fpihx'></tbody>
                    • <bdo id='fpihx'></bdo><ul id='fpihx'></ul>
                      1. <tfoot id='fpihx'></tfoot>
                        <i id='fpihx'><tr id='fpihx'><dt id='fpihx'><q id='fpihx'><span id='fpihx'><b id='fpihx'><form id='fpihx'><ins id='fpihx'></ins><ul id='fpihx'></ul><sub id='fpihx'></sub></form><legend id='fpihx'></legend><bdo id='fpihx'><pre id='fpihx'><center id='fpihx'></center></pre></bdo></b><th id='fpihx'></th></span></q></dt></tr></i><div id='fpihx'><tfoot id='fpihx'></tfoot><dl id='fpihx'><fieldset id='fpihx'></fieldset></dl></div>
                        <legend id='fpihx'><style id='fpihx'><dir id='fpihx'><q id='fpihx'></q></dir></style></legend>

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