Differentiate between Click or Drag on ng2-dragula

310 views Asked by At

On the demo page it is shown, that you can differentiate between a normal left click and the start of a drag.

Click or Drag! Fires a click when the mouse button is released before a mousemove event, otherwise a drag event is fired. No extra configuration is necessary.

I'm now using a isInDragMode variable, which is set on the drag event and unset in onSelect, but here it is stated that No extra configuration is necessary.

So is there a solution out of the box? How does it look like with ng2-dragula?

1

There are 1 answers

3
Padmapriya Vishnuvardhan On

You can try with the below way

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);