简体   繁体   English

骨干js中的自定义鼠标事件

[英]Custom mouse events in backbonejs

What would be a good way of supporting custom mouse events?支持自定义鼠标事件的好方法是什么? For example, I currently have:例如,我目前有:

events: {
  "mousedown .canvas-container" : "getPixel",
},

But instead of mousedown , I would like to create a custom event called mousedrag which would be a combination of mousedown and mousemove .但不是mousedown ,我想创建一个名为mousedrag的自定义事件,它是mousedownmousemove的组合。 Is there any recommended way of adding such a custom event?有没有推荐的方法来添加这样的自定义事件?

Since Backbone element events are simply jQuery ( or whatever library you use ) events, you might want to use jQuery UI : http://jqueryui.com/demos/draggable/ .由于 Backbone 元素事件只是 jQuery(或您使用的任何库)事件,您可能想要使用 jQuery UI: http : //jqueryui.com/demos/draggable/ By loading aside with jQuery and Backbone you will have "drag" event, which you could bind in your code, just like any other event :通过使用 jQuery 和 Backbone 加载,您将拥有“拖动”事件,您可以将其绑定到您的代码中,就像任何其他事件一样:

   events: { "drag .canvas-container" : "getPixel" }

Of course there is a way to create a custom events in jQuery, but I assume it is a lot of work for the draggable objects and since it is already written with cross-browser support it is better to use jQuery UI.当然,有一种方法可以在 jQuery 中创建自定义事件,但我认为对于可拖动对象需要做很多工作,而且由于它已经编写了跨浏览器支持,因此最好使用 jQuery UI。

PS jQuery UI is fully customizable, so you can build your own version on the site, which includes the specific methods you want : http://jqueryui.com/download PS jQuery UI 是完全可定制的,因此您可以在站点上构建自己的版本,其中包含您想要的具体方法: http : //jqueryui.com/download

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM