Hello there i got a html canvas and i want to add a scrollbar just like any web page or a textarea, i used overflow: scroll; but it only shows the scrollbars and they are disabled (and i can't scroll)
this is the markup
<div class="ccsp-area">
<canvas id="mainCanvas" width="900" height="500"></canvas>
</div>
and here is the css (scss)
.ccsp-area {
width: 90%;
height: 100%;
display: inline-block;
canvas {
display: inline-block;
background-color: #fff;
max-width: 100% !important;
overflow: scroll;
}
}
and finally this is the JS
var canvas = $("#mainCanvas");
var ctx = canvas[0].getContext('2d');
var targetSizeE = $(".ccsp-area");
var rwidth = targetSizeE.width() -200;
var rheight = targetSizeE.height() -80;
// no need to read more code after this stage
canvas.attr('width', rwidth);
canvas.attr('height', rheight);
ctx.beginPath();
ctx.moveTo(100 , 100);
ctx.lineTo(600, 600);
ctx.lineTo(600,100);
ctx.closePath();
ctx.lineWidth = 20;
ctx.strokeStyle = "rgba(10,220,50,1)";
ctx.fillStyle = "rgba(10,220,50,0.5)";
ctx.stroke();
a screen shot of the result result
as you can see, the scrollbars are disabled, and i can't scroll even when i have drawings inside the canvas which is more than the height of the canvas.