Cancel click event in the mouseup event handler

前端 未结 14 2467
梦毁少年i
梦毁少年i 2020-12-09 14:53

Writing some drag&drop code, I\'d like to cancel the click events in my mouseup handler. I figured preventing default should do the trick, but the click event is still f

14条回答
  •  醉话见心
    2020-12-09 15:36

    the solution that i use is the following:

    var disable_click = false;
    
    function click_function(event){
        if (!disable_click){
            // your code
        }
    }
    
    function mouse_down_function(event){
        disable_click = false; // will enable the click everytime you click
        // your code
    }
    
    function mouse_up_function(event){
        // your code
    }
    
    function mouse_drag_function(event){
        disable_click = true; // this will disable the click only when dragging after clicking
       // your code
    }
    

    attach each function to the appropriate event according to the name !

提交回复
热议问题