我想知道是否有办法在FabricJS的Textbox元素中选择文本的一部分? 目前,我正在使用
text.selectionStart = 0;
text.selectionEnd = 4;
但它选择第一行中的文字(理解为什么)。
如何让布料知道我需要从第二行选择那些?
TNX
答案 0 :(得分:1)
您可以使用结构中提供的insertCharStyleObject
方法。
代码段:
var selectionStart = 0;
var selectionEnd = 4;
var lineIndex = 1;
for (var i = selectionStart; i < selectionEnd; i++) {
text.insertCharStyleObject(lineIndex, i, {
textBackgroundColor: '#0F0'
})
}
更新了小提琴 - http://jsfiddle.net/4n4cLyvo/2/