使用 Raphaeljs 停止拖放事件

发布于 2024-09-30 18:28:24 字数 552 浏览 8 评论 0原文

我正在尝试用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

临走之时 2024-10-07 18:28:24

来自文档

要取消绑定事件,请使用带有“un”前缀的相同方法名称,即 element.unclick(f);

要取消绑定拖动,请使用 unrag 方法。

所以我认为 circle.undrag(); 应该有效。

From the documentation:

To unbind events use the same method names with “un” prefix, i.e. element.unclick(f);

and

To unbind drag use the undrag method.

So I would think circle.undrag(); should work.

大海や 2024-10-07 18:28:24

@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 ;)

我ぃ本無心為│何有愛 2024-10-07 18:28:24

如果您可以包含 jQuery,则可以在“mouseup”上使用 trigger。如果你不能包含 jQuery,也许只是看一下源代码并提升该功能?

更新

经过一些简短的谷歌搜索后,我发现了这个实现。不过仅在 Chrome 中进行了测试:

function fireEvent(element,event){
  if (document.createEventObject){
    // dispatch for IE
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt)
  } else{
    // dispatch for firefox + others
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true ); // event type,bubbling,cancelable
    return !element.dispatchEvent(evt);
  }
}

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:

function fireEvent(element,event){
  if (document.createEventObject){
    // dispatch for IE
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt)
  } else{
    // dispatch for firefox + others
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true ); // event type,bubbling,cancelable
    return !element.dispatchEvent(evt);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文