美好的一天,
想知道,对于fabric.js,在导入SVG的过程中,如何以编程方式设置' selectable'所有文本项都为false,但允许图像项保持可选?
fabric.loadSVGFromURL(urlString, function(objects, options) {
var group = fabric.util.groupSVGElements(objects, options);
canvas.add(group).centerObject(group).renderAll();
},
// set the 'selectable' values for each item
function(item, object) {
// how do I tell if the item is a text or image?
//psuedo code
if (item is text) {
object.selectable = false;
}
});
非常感谢任何帮助。
谢谢, 约翰尼
答案 0 :(得分:0)
如果要将所有文本对象设置为selectable = false,则只需遍历画布上的所有对象,然后使用“obj.get('type')”
测试对象的类型这是一个例子:
canvas.forEachObject(function(obj) {
if(obj.get('type') ==='text' || obj.get('type') ==='i-text') {
obj.selectable = false;
}
});