在Raphael JS Freetransform中隐藏手柄,但继续拖动?

4

你好,我正在开发一个需要使用Raphael JS和Raphael.Freetransform插件的新项目。到目前为止,该插件运行非常顺畅,但是使用hideHandles()方法后,似乎也禁用了对象的任何拖动形式。

这是一个错误还是设计选择?当我隐藏元素的手柄时,是否需要重新启用元素的拖动?我已经尝试过设置,但仍无法解决问题。是否有特定的方法可以使元素在不使用Freetransform插件的情况下可拖动?

以下是我的代码:

paper = new Raphael("container", "1680", "1005");
setA = paper.set();
circle = paper.circle(50, 50, 50);
circle.attr("fill", "#f00");
circle.attr("stroke", "#000");
notif = paper.circle(50, 50, 50);
notif.attr({ "fill": "r(0.5, 0.5) #fff-#f00", "fill-opacity": 1 });
lbl = paper.text(50, 50, "Label").attr({fill: '#000000'});
setA.push(circle);
setA.push(notif);
setA.push(lbl);

setA.click(function(){
    console.log('clicked');
});

setA.hover(
    // over //
    function (){ console.log('over'); }, 
    // out //
    function (){ console.log('out'); }
);

setA.drag(
    //onmove
    function(){  
        console.log('object moving');
    }, 
    //onstart
    function(){  
        console.log('start drag');
    }, 
    //onend
    function(){  
        console.log('end drag');
    }
);

ft = paper.freeTransform(setA, { drag: true, keepRatio: true, draw: [ 'bbox', 'circle' ] }, function(ft, events) { /*console.log(ft.attrs);*/ } );

$('#guideBtn').click(function(){
    if ($('#guideBtn').text().indexOf('Show') > -1){ ft.showHandles(); $('#guideBtn').text('Hide Guide'); }
    else{ ft.hideHandles(); $('#guideBtn').text('Show Guide'); }
});

这是一个免费的变换工具链接:https://github.com/ElbertF/Raphael.FreeTransform/

可以看到,我只是使用按钮的点击处理程序来显示和隐藏句柄。我需要跟进一步操作吗?

提前感谢, Conor

1个回答

6

我已经弄清楚了。与其调用.hideHandles()和.showHandles(),您可以简单地调用以下组合:{drag: true|false}、{scale: true|false}和{rotate: true|false}。

例如:

circle.setOpts({drag:'self', scale:false, rotate:false, draw:false});
circle.setOpts({drag:'self', scale:true, rotate:true, draw: [ 'bbox', 'circle' ]});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接