In this jsfiddle I have a Fabric.js text created with lockRotation: true
to avoid rotation. The line disappeared, but the box control to rotate is still there, how to get rid of it?
HTML
<canvas id="c" width="300" height="300"></canvas>
Javascript
var canvas = new fabric.Canvas('c');
var text = new fabric.IText('This is the text',{
left: 50,
top: 50,
fontFamily: 'Arial',
fontWeight: 'normal',
fontSize: 18,
lockRotation: true,
stroke: 'black',
fill: 'black'
});
The accepted answer is no longer valid with Fabricjs versions from 4.0 (see changelog). hasRotatingPoint
has been removed in favor of a more comprehensive controls api, although the documentation for it is still very slim.
To hide a certain control from a specific object, you have to redefine its controls
property. Here is how you would hide the mtr
control (Rotate):
text.controls = {
...fabric.Text.prototype.controls,
mtr: new fabric.Control({ visible: false })
}
var canvas = new fabric.Canvas('c');
var text = new fabric.IText('This is the text',{
left: 50,
top: 50,
fontFamily: 'Arial',
fontWeight: 'normal',
fontSize: 18,
stroke: 'black',
fill: 'black'
});
text.controls = {
...fabric.Text.prototype.controls,
mtr: new fabric.Control({ visible: false })
}
canvas.add(text);
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" width="300" height="300"></canvas>
Here we create a new controls object using the default ones for Text but redefining the mtr
set.
Use object.hasRotatingPoint = false; to hide rotating point.
var canvas = new fabric.Canvas('c');
var text = new fabric.IText('This is the text',{
left: 50,
top: 50,
fontFamily: 'Arial',
fontWeight: 'normal',
fontSize: 18,
hasRotatingPoint: false,
stroke: 'black',
fill: 'black'
});
canvas.add(text);
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c" width="300" height="300"></canvas>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With