我在JS中将我的fabricjs画布设置为canvas.setHeight(616);
canvas.setWidth(446);
,我想知道是否有一种方法可以让用户在onclick上更改这些尺寸,以便有一些选项?
答案 0 :(得分:1)
var canvas = new fabric.Canvas('a');
canvas.add(new fabric.Text('FabricJS is Awsome',{
left:50,
top:50
}));
function resizeCanvas(){
canvas.setHeight(canvas.height+50);
canvas.setWidth(canvas.width+50);
canvas.renderAll();
}
canvas {
border: 2px solid black;
}
<script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.19/fabric.js"></script>
<button onclick='resizeCanvas()'>Resize</button>
<canvas id="a" width="200" height="200"></canvas>
使用setHeight() / setWidth()分别设置高度和宽度。