我使用element.drag(start, move, up);
使元素可以拖动。
当我想让元素不可拖动时,可以参考文档中的方法:
element.undrag(f); // Any undefined variable works as the argument
这将使该元素无法再移动。
该方法有两个问题:
- 这使得页面上所有元素都无法拖动。
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);
};