繁体   English   中英

如何在Backbonejs视图方法中监听mousedown,mousemove和mouseup

[英]How to listen to mousedown, mousemove and mouseup in a Backbonejs view method

我希望能够在Backbone视图内拖动div元素。 为此,我需要在Backbone View方法内监听这三个事件mouseup,mousedown,mousemove。

    events: {
        "mousedown .status .progress .seek-bar .seek-bar-grip": "slide",
        "mouseup .status .progress .seek-bar .seek-bar-grip": "slide",
        "mousemove .status .progress .seek-bar .seek-bar-grip": "slide",
    },

    slide: function(event) {

        // Code about the drag here

    },

这是行不通的,因为每次触发另一个事件时,它将再次调用该方法。 我的问题不是如何在javascript中拖动div元素,而是如何在slide方法中收听这3个事件。

您可以使用幻灯片功能中的event.type区分事件。

var FLAG = 1;
var currentTarget;
slide: function(event) {        
        // Code about the drag here
        if(event.type = "mousedown"){
            FLAG = 2; // now handle mouse move
            currentTarget = event.currentTarget;
        }else if(event.type = "mousemove"){
            if(FLAG == 2){
                // use the currentTarget to doSomething()
            }
        }else if(event.type = "mouseup"){
            FLAG = 1;
                // drop the target
        }
    },

暂无
暂无

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

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