Is there any chance to add padding and border radius on Fabric JS background text i want to look like call to action button
JS
canvas = new fabric.Canvas('mainCanvas',
backgroundColor: 'green'
)
text = new fabric.IText('hello world',
left: 200
top: 100
backgroundColor: "pink",
)
canvas.add(text)
HTML
<canvas id="mainCanvas" style="border:1px solid #aaa" width="600" height="300"></canvas>
JSFIDDLE
I solved the problem by simply grouping the elements and in fabric.Rect
I added rx: 5
and ry: 5
for border radius.
There is all the code JSFIDDLE
var canvas = window._canvas = new fabric.Canvas('c1');
var bg = new fabric.Rect({
fill: '#32b775',
scaleY: 0.5,
originX: 'center',
originY: 'center',
rx: 5,
ry: 5,
width: 90,
height:80
});
var text = new fabric.Text('Done', {
fontSize: 18,
originX: 'center',
originY: 'center',
fill: '#FFF'
});
var group = new fabric.Group([ bg, text ], {
left: 50,
top: 100
});
canvas.add(group);
canvas {
border: 1px solid #999;
}
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="c1" 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