你如何使一个元素无法在拉斐尔? [英] How do you make an element undragable in Raphael?

查看:121
本文介绍了你如何使一个元素无法在拉斐尔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

当我想要使元素无法复原,我可以使用 文档中的方法来实现这一点

When I want to make the element undragable, I can somewhat achieve this using the method from the documentation:

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

这样使得元素不能再被移动了。

This makes it so that the element cannot be moved anymore.

此方法有2个问题:


  1. 这使得 / strong>页面上的元素无法复原。

  2. start()每个元素仍然会触发一次。我在 start()中触发了不透明度更改,所以很明显。

  1. This makes all elements on the page undragable.
  2. start() still fires once for each element. I have an opacity change triggered in start() so it's quite obvious.

如何使元素无法复原,以便仅该元素受到影响, start()不会被触发?

How do I make an element undragable so that only that element is affected and start() is not fired?

这是我到目前为止。以下尝试在拖动后使该元素无法复原:

Here's what I have so far. The following tries to make the element undragable after one drag:

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);     
};​



尝试用这个jsFiddle


推荐答案

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

This is known bug. Will be fixed in the next release.

这篇关于你如何使一个元素无法在拉斐尔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆