【问题标题】:Multiple object in a clipping section in fabric Js canvas织物Js画布中剪辑部分中的多个对象
【发布时间】:2015-12-14 02:52:22
【问题描述】:

我在画布中添加了一个剪辑部分。 我正在为此添加多个对象。 问题是,一旦我添加了第二个对象,第一个对象就会变得不可见。

在此解释

var pug = new fabric.Text("Hi ", {
        angle: 0,
        width: 500,
        height: 500,
        left: 245,
        top: 35,
        scaleX: 0.3,
        scaleY: 0.3,
        clipName: 'pug',
        clipTo: function(ctx) { 
            ctx.save();
              ctx.setTransform(1, 0, 0, 1, 0, 0);
              ctx.rect(
                100, 100,
                200, 200
              );
            clipRect1.render(ctx);
            ctx.strokeStyle = "red";
            ctx.stroke();
              ctx.restore();
        }
    });
    canvas.add(pug);

    var pug1 = new fabric.Text("Hello", {
        angle: 0,
        width: 500,
        height: 500,
        left: 300,
        top: 35,
        scaleX: 0.3,
        scaleY: 0.3,
        clipName: 'pug',
        clipTo: function(ctx) { 
            ctx.save();
              ctx.setTransform(1, 0, 0, 1, 0, 0);
              ctx.rect(
                100, 100,
                200, 200
              );
            clipRect1.render(ctx);
            ctx.strokeStyle = "red";
            ctx.stroke();
              ctx.restore();
        }
    });
    canvas.add(pug1);

http://jsfiddle.net/ZxYCP/202/

【问题讨论】:

    标签: javascript canvas fabricjs


    【解决方案1】:

    将剪切区域背景更改为透明(第 17 行)。 当 FabricJS 呈现第二个对象时,它会与第一个对象重叠。

    【讨论】:

    • 是的,这行得通。但是有没有办法在剪辑部分填充颜色?
    • 尝试在底部添加填充了所需背景的矩形。将选项“可选择”和“事件”设置为 false,以防止用户选择它。
    • 我保持 fill = transparent 和 backgroundColor "#DDD" ,但没有用
    • 不,你不明白我的意思。您应该创建具有所需背景的附加对象 fabric.Rect 并通过您的剪切区域对其进行剪切。
    • 我还是没听懂你,你能在我的小提琴中更新你的变化吗?
    猜你喜欢
    • 2016-05-04
    • 2017-11-14
    • 2021-01-24
    • 2018-12-18
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 2019-12-12
    相关资源
    最近更新 更多