鼠标拖动检测

添加一个标识,判断检测鼠标是否移动

var flag = 0;
var element = xxxx;
element.addEventListener("mousedown", function(){
    flag = 0;
}, false);
element.addEventListener("mousemove", function(){
    flag = 1;
}, false);
element.addEventListener("mouseup", function(){
    if(flag === 0){
        console.log("click");
    }
    else if(flag === 1){
        console.log("drag");
    }
}, false);

 

posted @ 2019-05-29 15:02  余生以学  阅读(1218)  评论(1编辑  收藏  举报