raphael icon indicating copy to clipboard operation
raphael copied to clipboard

element.drag and element.click conflict

Open clawfire opened this issue 10 years ago • 5 comments

I got some trouble with binding a drag event and a click event on the same elements :

set.click( function(){
    this.remove().clear();
});

set.drag(function(dx,dy){...},function(){...},function(){...});

when the drag end, the click event is catched ... any idea ?

clawfire avatar Nov 19 '14 15:11 clawfire

@clawfire I am currently running into the same issue. Any solutions?

westoque avatar Dec 18 '14 10:12 westoque

you can add click event to drag event in the third parameter "onend",I tested when I clicked the element,the drag event "onstart" & "onend" happend,and you can set a flag ,when the event through the "onmove" you can set change the flag,I sorry my english is so poor,I must paste the code.

                            var tz_tag = true;
            elem.drag(function(dx,dy,x,y,event){

                tz_tag = false;

            },function(x,y,event){
                //拖动开始

            },function(event){
                //拖动结束
                    if(tz_tag){
                                                //do something
                                         }
                    tz_tag = true;


            });

YealZoy avatar Jan 12 '16 10:01 YealZoy

I confirm this issue

tobiascapin avatar Apr 11 '16 09:04 tobiascapin

I completely agree @YealZoy . Setting multiple events does nothing but appends the events into an array of events to be listened. Click is nothing but a mouseMove not being fired in the drag event.

@tobiascapin If we are stating this as an issue, then what should be the ideal behaviour for the snippet and what solution we might derive from it.

AyanGhatak avatar May 01 '16 05:05 AyanGhatak

For me a click event is a fast mouseDown+mouseUp without mouseMove between these events. During my tests I found that a click event is fired at mouseup at the end of the drag, for me this is an issue. If I'm dragging I'm not cliccking.

Let's say that I select an element with click and I want to move selected element with drag, the effect is that at drag end I lose element selection because an unwanted click is fired on it (I made a workaround with a "isDragging" flag, with this flag I ignore a click if I'm dragging the element).

tobiascapin avatar May 01 '16 10:05 tobiascapin