Search code examples
javascriptd3.jsevent-handlingdom-eventsevent-bubbling

How to prevent triggering mouseleave after mouseup?


In my Javascript app I am having issues with event bubbling, namely I would like not to trigger mouseleave after mouse up on an element (have implemented dragging behavior therefore it moves and mouse leaves it).

How can I do that ?

EDIT

I am using d3.js to capture event in the following way :

d3.selectAll("circle")
        .on("mouseover", function(d,i){
        ...
        }
        .on("mouseup", function(d,i){
        ...
        }
        .on("mouseleave", function(d,i){
        ...
        }

Solution

  • I have solved it in similar way to user1671639's adivice with boolean check :

    var been_in_mouseup = false;
    
    .on("mousedown", function(d){
        ...
        been_in_mouseup = false;
    })
    .on("mouseup", function(d,i){
        ...
        been_in_mouseup = true;
    })
    .on("mouseleave", function(d, i){
        ...
        if(false == been_in_mouseup )
        {
        ...
        }
    })
    

    EDIT

    Is there any more elegant way to do this ?