2017-09-29 62 views

回答

1

var canvas = new fabric.Canvas('canvas'); 
 
var text = new fabric.Text('FabricJS is Awsome.',{ 
 
fontSize:'30', 
 
left:50, 
 
top:50, 
 
underline:true 
 
}); 
 
canvas.add(text); 
 
//text.setSelectionStyles({overline:true},0,5); 
 
canvas.renderAll(); 
 
function changeStyle(val){ 
 
text[val] = !text[val]; 
 
text.dirty = true; 
 
canvas.renderAll(); 
 
}
canvas { 
 
    border: 2px dotted green; 
 
}
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script> 
 
<button onclick=changeStyle('underline')>underline</button> 
 
<button onclick=changeStyle('overline')>overline</button> 
 
<button onclick=changeStyle('linethrough')>linethrough</button><br> 
 
<canvas id="canvas" width="400" height="400"></canvas>

同其他屬性集/從對象中獲取。 fabric.Text

+0

優秀。非常感謝你! –

+0

@SandorRozsa upvote並標記是否這是你想要的。乾杯;) – Durga

+0

對不起durga - 錯過了那個... :-) –