首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >underscore.js解绑

underscore.js解绑
EN

Stack Overflow用户
提问于 2011-04-08 20:54:23
回答 1查看 3.2K关注 0票数 2

我很乐意解开这一点:

代码语言:javascript
复制
$("body").mousemove(_.bind(this.mousemove, this));

由于backbone.js和raphael.js之间的复杂混合,我需要通过underscore.js进行绑定:

代码语言:javascript
复制
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;
        }
    });

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-08 21:33:08

感谢@Pointy (谢谢:D):

解决方案很简单:$("body").unbind("mousemove");

请参阅第一篇文章中的评论。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5595327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档