underscore.js 解除绑定
我很想解除绑定:
$("body").mousemove(_.bind(this.mousemove, this));
由于backbone.js和raphael.js之间的复杂混合,我需要通过underscore.js进行绑定:
var NodeView = Backbone.View.extend({
dx: 0,
dy: 0,
click: function(event){
alert('hello')
},
mousedown: function(event){
this.dx = event.pageX - this.el.attr('x');
this.dy = event.pageY - this.el.attr('y');
this.el.attr({fill: "#0099FF"});
$("body").mousemove(_.bind(this.mousemove, this));
},
mousemove: function(event){
this.el.attr({ x: event.pageX - this.dx,
y: event.pageY - this.dy});
},
mouseup: function(event){
this.el.attr({fill: "#EEEEEE"});
$("body").mousemove(_.bind(this.mousenotmove, this));
},
render: function(){
this.el = canvas.rect(this.model.get('xPos'), this.model.get('yPos'), 50, 50).attr({
fill: "#EEEEEE",
stroke: "none",
cursor: "move"
});
$(this.el.node).mousedown(_.bind(this.mousedown, this));
$(this.el.node).mouseup(_.bind(this.mouseup, this));
return this;
}
});
有什么建议吗?
I would love to unbind this:
$("body").mousemove(_.bind(this.mousemove, this));
Due to a complicated mix between backbone.js and raphael.js I need to do the bind via underscore.js:
var NodeView = Backbone.View.extend({
dx: 0,
dy: 0,
click: function(event){
alert('hello')
},
mousedown: function(event){
this.dx = event.pageX - this.el.attr('x');
this.dy = event.pageY - this.el.attr('y');
this.el.attr({fill: "#0099FF"});
$("body").mousemove(_.bind(this.mousemove, this));
},
mousemove: function(event){
this.el.attr({ x: event.pageX - this.dx,
y: event.pageY - this.dy});
},
mouseup: function(event){
this.el.attr({fill: "#EEEEEE"});
$("body").mousemove(_.bind(this.mousenotmove, this));
},
render: function(){
this.el = canvas.rect(this.model.get('xPos'), this.model.get('yPos'), 50, 50).attr({
fill: "#EEEEEE",
stroke: "none",
cursor: "move"
});
$(this.el.node).mousedown(_.bind(this.mousedown, this));
$(this.el.node).mouseup(_.bind(this.mouseup, this));
return this;
}
});
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢@Pointy(谢谢:D):
解决方案很简单: $("body").unbind("mousemove");
请参阅第一篇文章中的评论。
Thanks to @Pointy (thank you :D):
The solution is a simple as: $("body").unbind("mousemove");
See comments in first post.