admin管理员组

文章数量:1410717

I want to get the real object width and height while I am scaling the object. I tried with

canvas.on('object:scaling', function(e){
  console.log(e.target.width*e.target.scaleX);
});

But seem that does not work properly.

I want to get the real object width and height while I am scaling the object. I tried with

canvas.on('object:scaling', function(e){
  console.log(e.target.width*e.target.scaleX);
});

But seem that does not work properly.

Share Improve this question edited May 11, 2018 at 9:44 Durga 15.6k2 gold badges30 silver badges54 bronze badges asked May 11, 2018 at 8:09 Pedro JosePedro Jose 4425 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Use object.getScaledWidth().

DEMO

var canvas = new fabric.Canvas("c");
var circle = new fabric.Circle({radius:100})
canvas.add(circle);
circle.on('scaling',function(){
 console.log(parseInt(this.getScaledWidth()))
})
canvas{
  border: 1px dotted green;
}
<script src="https://rawgit./kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" width=400 height=400></canvas>

本文标签: javascriptget scaled width on objectscalingStack Overflow