使用 Raphaeljs 停止拖放事件
我正在尝试用 Raphaeljs 模拟 iPhone 的滑动事件。 为此,我使用拖放事件。
要模拟该事件,请在移动事件中使用一个方法来计算我的对象和鼠标位置之间的距离。如果鼠标经过该距离,我想停止拖放事件。这就是我被困住的地方。
这是代码:
var start = function (event) {
},
move = function (event) {
inrange = self.inRange (circle.attr("cx"), circle.attr("cy"), event.pageX, event.pageY);
if(inrange == false){
//Stop draging!
}
},
up = function () {
circle.animate({ r: 40, "stroke-width": 1 }, 200);
};
circle.drag(move, start, up);
在 move 方法中,我需要停止拖动事件或模拟鼠标悬停。我怎样才能这样做呢?
I am trying to simulate the swipe event from the iPhone with Raphaeljs.
To do so, I am using the drag and drop event.
To simulate the event in have a method in the move event that calculate the distance between my object and the mouse position. If the mouse goes after that distance I want to stop the drag and drop event. This is where I'm stuck.
Here is the code:
var start = function (event) {
},
move = function (event) {
inrange = self.inRange (circle.attr("cx"), circle.attr("cy"), event.pageX, event.pageY);
if(inrange == false){
//Stop draging!
}
},
up = function () {
circle.animate({ r: 40, "stroke-width": 1 }, 200);
};
circle.drag(move, start, up);
In the move method I need the stop the drag event or simulate a mouseup
. How can I do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自文档:
和
所以我认为
circle.undrag();
应该有效。From the documentation:
and
So I would think
circle.undrag();
should work.@Gregory您可以使用JS闭包来检测圆圈是否需要停止拖动。 @apphacker Raphael 中有一个已知问题,导致 undrag 无法工作。它计划在 2.0 中修复,但目前还没有发布日期(并且该 bug 并未在 beta 代码中修复,尽管票证上说已修复。
我建议手动实现 mousedown、mouseup 和 添加 JS 关闭检查,以查看圆圈是否需要停止拖动。
根据 @floyd 的建议,使用 jQuery 进行 mousemove 事件,并在移动函数中 '10,所以从那时起你可能已经继续前进了;)
@Gregory You can use a JS closure to detect if the circle needs to stop dragging. And @apphacker there is a known issue in Raphael that prevents undrag from working. It is scheduled to be fixed in 2.0, but that doesn't have a release date as of yet (and the bug isn't fixed in the beta code, despite the ticket saying it is.
I recommend manually implementing the mousedown, mouseup and mousemove events using jQuery, as per @floyd's recommendation, and add a JS closure check in your move function to see if the circle needs to stop being dragged yet or not.'
It also occurs to me that your original post was last edited in Nov '10, so you might have moved on since then ;)
如果您可以包含 jQuery,则可以在“mouseup”上使用 trigger。如果你不能包含 jQuery,也许只是看一下源代码并提升该功能?
更新
经过一些简短的谷歌搜索后,我发现了这个实现。不过仅在 Chrome 中进行了测试:
If you can include jQuery you can use trigger on "mouseup." If you can't include jQuery maybe just take a look at the source and lift that one function?
UPDATE
After some brief googling I came across this implementation. Only tested in in Chrome though: