0
我想要更改矩形度量值,其中输入的值为高度和宽度。但函数重新计算(inputWidth,inputHeight)失败。谁能帮我 ?Fabric js:使用值插入修改矩形高度和宽度
这里是我的html代码:
<div class="row">
<div class="col-sm-3">
<form>
<div class="form-group">
<label for="inputHeight">Height</label>
<input type="text" name="inputHeight" class="form-control">
</div>
<div class="form-group">
<label for="inputWidth">Width</label>
<input type="text" name="inputWidth" class="form-control">
</div>
<button onclick="recalculate(inputWidth, inputHeight)" type="submit" class="btn btn-primary squareP">Modify Rectangle</button>
<button type="button" class="btn btn-primary square">Rectangle</button>
</form>
</div>
<div class="col-sm-9">
<canvas id="myCanvas"></canvas>
</div>
这里的javascript:
var canvas = new fabric.Canvas('myCanvas', {
width: window.innerWidth,
height: window.innerWidth - 50,
isDrawingMode: false,
backgroundColor: '#fff'
});
document.querySelectorAll('.square')[0].addEventListener('click', function() {
var rect = new fabric.Rect({
top: 100,
left: 100,
width: 100,
height: 100,
fill: '',
selection: false,
fill: '#f55'
});
canvas.add(rect);
});
document.body.querySelectorAll('.squareP')[0].addEventListener('click', function recalculate(inputWidth, inputHeight) {
var obj = canvas.getActiveObject();
obj.set('width', inputWidth).set('height', inputHeight);
obj.set({width: inputWidth.value, height: inputHeight.value});
obj.setCoords();
canvas.renderAll();
});