带滚动条的 HTML 画布 [英] HTML canvas with scrollbar

查看:36
本文介绍了带滚动条的 HTML 画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在宽度不等的画布上绘制图形.每个画布都可以有自己的滚动条吗?我试图将所有画布放在一个 div 中并指定一个最大宽度,但没有用.是否有可能所有画布在页面上的可见宽度都是 500 像素,并且每个画布都有自己的滚动条来查看画布的整个宽度.

谢谢.

解决方案

指定画布的总宽度,然后将其包裹在一个 div 中.将 div 设置为 overflow: scroll 并指定 500px 宽度.然后你应该有滚动条,允许你滚动并查看画布的隐藏部分.对所有画布重复此操作.

<div style="max-height: 256px;max-width:256px;overflow: scroll;"><canvas width="512px" height="512px"></canvas>

I am drawing graphs on canvases which have large unequal widths. Is it possible for each canvas to have its own scrollbar? I tried to put all the canvases in one div and specify a max-width but it didn't work. Is it possible for all the canvases to be say 500px in visible width on the page and each has its scrollbar to view the entire width of the canvas.

Thank you.

解决方案

Specify the total width of the canvas then wrap it in a div. Set the div to overflow: scroll and give that the 500px width. You should then have scrollbars allowing you to scroll and see the hidden parts of the canvas. Repeat this for all of the canvases.

<div style="max-height: 256px;max-width:256px;overflow: scroll;">
          <canvas width="512px" height="512px"></canvas>
</div>   

这篇关于带滚动条的 HTML 画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆