简体   繁体   English

json.stringify:调整对象大小后,高度和宽度属性不会更新

[英]json.stringify: After resizing of an object height and width properties are not updated

Next code create triangles on canvas, if you are not clicking over an existing triangle. 如果未单击现有三角形,则下一个代码在画布上创建三角形。 And you may save all elements to JSON with clicking on "save" button.Then preview the JSON variable in console. 您可以通过单击“保存”按钮将所有元素保存为JSON。然后在控制台中预览JSON变量。

My problem is that after resizing of an object, height and width are not updated in Json, when clicked on save again. 我的问题是,调整对象大小后,再次单击保存时,Json中的高度和宽度不会更新。 To resize the triangle You have to click on it. 调整三角形的大小您必须单击它。 Then grab one of the anchor rectangles and drag it from the center of triangle. 然后抓住一个锚定矩形,并将其从三角形的中心拖动。

What action must I perform to have also new height and width of the object? 我还应该执行什么操作才能使对象具有新的高度和宽度?

Next is code snippet on jsFfidle: https://jsfiddle.net/ug7p9myc/76/ 接下来是jsFfidle上的代码段: https ://jsfiddle.net/ug7p9myc/76/

 var canvas = new fabric.Canvas('c5'); function some1(x1, y2) { var c = new fabric.Triangle({ left: posX2, top: posY2, width: 15, height: 25, strokeWidth: 3, fill: '#666', stroke: '#666' }); canvas.add(c); } var posX2, posY2; canvas.on('mouse:down', function(e) { var pointer = canvas.getPointer(ee); posX2 = pointer.x; posY2 = pointer.y; if (e.target) {} else { some1(posY2, posY2); } }); function saveJsonF() { var jsonToPHP = JSON.stringify(canvas.toObject()); console.log(jsonToPHP); } document.getElementById("saveJsonID").onclick = saveJsonF; 
 <script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.22/fabric.min.js"></script> <input type="button" class="Btn1" id="saveJsonID" value="Save" /></br><br> <canvas id="c5" width="1060" height="550" style="border: 1px solid black"></canvas> 

Use getScaledWidth and getScaledHeight to get the transformed values. 使用getScaledWidthgetScaledHeight获取转换后的值。 If you scale an object, its scaleX and scaleY value changes. 如果缩放对象,则其scaleX和scaleY值会更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM