你好,我有一个html画布,我想添加一个滚动条,就像任何网页或文本区域一样,我使用了溢出:滚动;但是它只显示滚动条,并且它们是禁用的(而且我不能滚动)
这是标记
<div class="ccsp-area">
<canvas id="mainCanvas" width="900" height="500"></canvas>
</div>这是css (scss)
.ccsp-area {
width: 90%;
height: 100%;
display: inline-block;
canvas {
display: inline-block;
background-color: #fff;
max-width: 100% !important;
overflow: scroll;
}
}最后这是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();结果结果的屏幕截图
正如您所看到的,滚动条是禁用的,即使在画布中有超过画布高度的绘图时,我也不能滚动。
发布于 2016-07-14 09:39:58
就像那个家伙说的,画布没有内容可以溢出,所以最好的方法是将画布的宽度和高度设置为很大的东西,比如2200 x 1500 (你可以通过js改变高度)。
这就是你的css应该看起来的样子。
.ccsp-area {
width: 90%;
height: 100%;
display: inline-block;
overflow: scroll;
canvas {
display: inline-block;
background-color: #fff;
}
}在您的情况下,从html元素中设置大小,而不是从JS中设置大小(也可以随意删除设置画布大小的js代码)。
<canvas id="mainCanvas" width="900" height="500"></canvas>发布于 2016-07-14 07:08:57
参见链接这里
您可以分别设置overflow-x和overflow-y。
查看有关MDN溢出的更多信息
https://stackoverflow.com/questions/38366947
复制相似问题