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

      <tfoot id='UvRnY'></tfoot>

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

      2. <legend id='UvRnY'><style id='UvRnY'><dir id='UvRnY'><q id='UvRnY'></q></dir></style></legend>
          <bdo id='UvRnY'></bdo><ul id='UvRnY'></ul>

        画布底部有空白区域并且滚动太远

        时间:2023-06-22

      3. <small id='5k8tU'></small><noframes id='5k8tU'>

        1. <legend id='5k8tU'><style id='5k8tU'><dir id='5k8tU'><q id='5k8tU'></q></dir></style></legend>

            <tfoot id='5k8tU'></tfoot>
              <tbody id='5k8tU'></tbody>
            • <i id='5k8tU'><tr id='5k8tU'><dt id='5k8tU'><q id='5k8tU'><span id='5k8tU'><b id='5k8tU'><form id='5k8tU'><ins id='5k8tU'></ins><ul id='5k8tU'></ul><sub id='5k8tU'></sub></form><legend id='5k8tU'></legend><bdo id='5k8tU'><pre id='5k8tU'><center id='5k8tU'></center></pre></bdo></b><th id='5k8tU'></th></span></q></dt></tr></i><div id='5k8tU'><tfoot id='5k8tU'></tfoot><dl id='5k8tU'><fieldset id='5k8tU'></fieldset></dl></div>
                  <bdo id='5k8tU'></bdo><ul id='5k8tU'></ul>
                  本文介绍了画布底部有空白区域并且滚动太远的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用这个答案 https://stackoverflow.com/a/36233727/1350146 来滚动画布在一个div中.我也隐藏了滚动条.问题是它似乎滚动得太远了,在这种情况下,如果您向下滚动,您可以看到画布所在的 div 的红色.

                  I'm using this answer https://stackoverflow.com/a/36233727/1350146 to scroll a canvas in a div. I'm also hiding the scrollbar. The problem is it appears to scroll too far, in this case if you scroll down you can see the red of the div the canvas is in.

                  我试过搞乱填充 &边距和不同的大小,但没有运气.

                  I've tried messing with padding & margins and different sizes but no luck.

                  var c = document.getElementById("myCanvas");
                  var ctx = c.getContext("2d");
                  ctx.fillStyle = '#00aa00'
                  ctx.fillRect(0, 0, c.width, c.height);
                  ctx.fillStyle = '#fff'
                  ctx.font='12pt A'
                  ctx.fillText("scroll here to see red from screen div", 30, 50);

                  .screen {
                    background: red;
                    height: 100px;
                    width: 300px;
                    overflow: auto;
                    border-radius: 20px;
                    
                  }
                  
                  ::-webkit-scrollbar {
                    width: 0px;
                    height: 0px;
                  }

                  <div class="screen">
                    <canvas id="myCanvas" width="300" height="120">
                    </canvas>
                  </div>

                  如何让它滚动到画布的末尾而不显示下面的任何容器 div?

                  How can I make it scroll just to the end of the canvas and not show any of the container div underneath?

                  谢谢!

                  推荐答案

                  使画布成为 block 元素或使用 vertical-align:top.默认情况下,canvas 是一个内联元素,它的行为类似于 img;因此,由于垂直对齐,您将遇到空白问题(内部图像div 在图片下方有多余的空间)

                  Make the canvas a block element or use vertical-align:top. By default, canvas is an inline element and it will behave similary to an img; thus you will have the whitespace issue due to vertical alignement (Image inside div has extra space below the image)

                  var c = document.getElementById("myCanvas");
                  var ctx = c.getContext("2d");
                  ctx.fillStyle = '#00aa00'
                  ctx.fillRect(0, 0, c.width, c.height);
                  ctx.fillStyle = '#fff'
                  ctx.font='12pt A'
                  ctx.fillText("scroll here to see red from screen div", 30, 50);

                  .screen {
                    background: red;
                    height: 100px;
                    width: 300px;
                    overflow: auto;
                    border-radius: 20px;
                  }
                  canvas {
                   display:block;
                  }
                  
                  ::-webkit-scrollbar {
                    width: 0px;
                    height: 0px;
                  }

                  <div class="screen">
                    <canvas id="myCanvas" width="300" height="120">
                    </canvas>
                  </div>

                  这篇关于画布底部有空白区域并且滚动太远的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何修复 getImageData() 错误画布已被跨域数据污染? 下一篇:如何修复 HTML5 画布中的模糊文本?

                  相关文章

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