答案 0 :(得分:5)
一种方法是监视scaling
事件并将Rect的比例重置为1,改为修改其width
和height
:
const canvas = new fabric.Canvas('c')
const rect = new fabric.Rect({
left: 10,
top: 10,
width: 100,
height: 100,
fill: 'blue',
rx: 10,
ry: 10,
objectCaching: false,
})
rect.on('scaling', function() {
this.set({
width: this.width * this.scaleX,
height: this.height * this.scaleY,
scaleX: 1,
scaleY: 1
})
})
canvas.add(rect).renderAll()
canvas {
border: 1px solid red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.22/fabric.js"></script>
<canvas id="c" width="300" height="250"></canvas>