如何在Raphael中使元素无法拖动?

3

我使用element.drag(start, move, up);使元素可以拖动。

当我想让元素不可拖动时,可以参考文档中的方法:

element.undrag(f); // Any undefined variable works as the argument

这将使该元素无法再移动。

该方法有两个问题:

  1. 这使得页面上所有元素都无法拖动。
  2. start()仍然会为每个元素触发一次。我在start()中触发了一个不透明度改变,所以这很明显。

如何使一个元素不可拖动,以便只影响该元素,并且不会触发start()

这是我现在有的。以下代码尝试在一次拖动后使元素不可拖动:

wiwindow.onload = function() {
    var R = Raphael("canvas", 500, 500),
    c = R.circle(100, 100, 50).attr({
        fill: "hsb(.8, 1, 1)",
        stroke: "none",
        opacity: .5
    }),
    d = R.circle(200, 200, 50).attr({
        fill: "hsb(1, 1, .8)",
        stroke: "none",
        opacity: .5
    }),        
    start = function () {
        // storing original coordinates
        this.ox = this.attr("cx");
        this.oy = this.attr("cy");
        this.attr({opacity: 1});
    },
    move = function (dx, dy) {
        // move will be called with dx and dy
        this.attr({cx: this.ox + dx, cy: this.oy + dy});
    },
    up = function () {
        // restoring state
        this.attr({opacity: .5});
        this.undrag(notDefinedVariable); // Try to make it undragable
    };

    c.drag(move, start, up);    
    d.drag(move, start, up);     
};​

Try it out with this jsFiddle


1
这个问题已经解决了吗? - Falak
@user880479 我正在使用与上面相同的2.0版本的fiddle,但它仍然无法工作。 - AHungerArtist
@AHungerArtist - 在2.0中让它工作了 - 我有一些奇怪的“notDefinedVariable”==> http://jsfiddle.net/pajtai/VBVWa/ - 它必须在之前的版本中包含才能正常工作。 - Peter Ajtai
2个回答

3

我已经在 2.0 中使其正常工作。

我不得不进行更改。

this.undrag(notDefinedVariable); // Try to make it undragable

为了

this.undrag(); // Try to make it undragable

在之前的版本中,必须包含Undefined才能使其像上面描述的那样工作得一半。


2

这是一个已知的 bug。将在下一个版本中修复。


谢谢你的回答,Dmitry。你有任何想法关于下一个版本什么时候会发布吗?顺便说一句,这是一个非常棒的库;玩起来很有趣。 - Peter Ajtai
这应该会在11月的Sencha Conference之前发生,但我不做任何承诺。这将是一个重大的1.6版本发布。 - Dmitry Baranovskiy
1
@DmitryBaranovskiy 就记录而言,使用与上面链接相同的fiddle,Raphael 2.0仍然显示此错误。我正在使用最新版本的Raphael,也遇到了这个问题。 - AHungerArtist

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