我想解开这个:
$("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;
}
});
有什么建议吗?
答案 0 :(得分:3)
感谢@Pointy(谢谢你:D):
解决方案很简单:$(“body”)。unbind(“mousemove”);
请参阅第一篇文章中的评论。