我有一個(gè)織物矩形,我想手動(dòng)更改寬度和高度。接下來(lái)的問(wèn)題是:當(dāng)我第一次通過(guò)縮放調(diào)整ctsize時(shí),它會(huì)按預(yù)期調(diào)整大小,但是在此之后,我嘗試更改輸入中的值 - 矩形以錯(cuò)誤的尺寸重新呈現(xiàn),但javascript對(duì)象中的寬度和高度值正確。法典:<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.3/fabric.min.js"></script><canvas id="draw"></canvas>width:<input type="number" id="w" value="50">var w = document.getElementById('w');var c = new fabric.Canvas('draw');var rect = new fabric.Rect({ top: 50, left: 50, width: parseInt(w.value), height: parseInt(h.value), fill: 'lightblue', type: 'rect'});c.add(rect);c.renderAll();c.on('object:scaling', function(e) { var width = parseInt(e.target.width * e.target.scaleX); w.value = width;});w.addEventListener('change', function(e) { rect.set('width', parseInt(e.target.value)); rect.setCoords(); c.requestRenderAll();});
FabricJS:如何手動(dòng)設(shè)置對(duì)象的寬度和高度
慕工程0101907
2022-08-18 15:36:07