如何发送落后&在fabricjs中引入一个活跃的群体

时间:2015-10-16 09:59:07

标签: javascript html5 canvas fabricjs

我正试图向后发送&点击面料js中的按钮,提出一个活动对象/活动组,我可以向后发送一个活动对象,但在组中出现问题。
这是我的代码

    $('#send-backward').click(function() { 
            var activeObject=canvas.getActiveObject(),
                activeGroup=canvas.getActiveGroup();
            if (activeObject) {
                canvas.sendBackwards(activeObject);
                canvas.renderAll();
                }
            else if (activeGroup) {
                  canvas.getActiveGroup().forEachObject(function(o){canvas.sendBackwards(o); });
//activeGroup.sendBackwards();
                  canvas.renderAll();
                } 
             });

    $('#bring-forward').click(function() { 
        var activeObject=canvas.getActiveObject(),
            activeGroup=canvas.getActiveGroup();
        if (activeObject) {
            canvas.bringForward(activeObject);
            canvas.renderAll();
            }
        else if (activeGroup) {
              canvas.getActiveGroup().forEachObject(function(o){canvas.bringForward(o); });
//activeGroup.bringForward();
              canvas.renderAll();
            }

         });

Jsfiddle 用这个代码提出是可以的,但是向后发送的问题
另一个代码尝试是 jsfiddle这段代码很奇怪,它制作了一个组的副本

在此先感谢您的帮助

3 个答案:

答案 0 :(得分:2)

您可以直接使用w1 = Text(self, undo=True, height=1, width=26,wrap=NONE) w1.grid(row=0, column=1, padx=5, pady=5, sticky=W) w1.bind('<Return>', self.parse) 相应的activeGroup.sendBackwards()

答案 1 :(得分:0)

1.7.3版activeGroup.sendBackwards()&amp;&amp; activeGroup.bringForward()

我的工作不正常,所以我在这里发布小提琴,其中 sendToBack &amp;&amp; bringToFront 非常适合

https://stackoverflow.com/a/41879620/1390678

答案 2 :(得分:0)

document.getElementById('tofront').addEventListener("click",enviarFrente);
function enviarFrente()
{
    var myObject = canvas.getActiveObject();
    canvas.bringToFront(myObject);
    canvas.discardActiveObject();
canvas.renderAll(); 
}


document.getElementById('toback').addEventListener("click",enviarFondo);
function enviarFondo()
{
  var myObject = canvas.getActiveObject();
  canvas.sendToBack(myObject);
  canvas.discardActiveObject();
canvas.renderAll(); 
}

document.getElementById('toAdelante').addEventListener("click",moverAdelante);
function moverAdelante()
{
  var myObject = canvas.getActiveObject();
  canvas.bringForward(myObject);
  canvas.discardActiveObject();
canvas.renderAll(); 
}

document.getElementById('toAtras').addEventListener("click",enviarAtras);
function enviarAtras()
{
  var myObject = canvas.getActiveObject();
  canvas.sendBackwards(myObject);
  canvas.discardActiveObject();
canvas.renderAll(); 
}