HTML canvas with scrollbar

2019-01-12 04:18发布

问题:

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.

回答1:

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>