drag and drop, prevent awkward highlighting?

后端 未结 2 437
别跟我提以往
别跟我提以往 2021-02-09 06:22

I\'m building a drag and drop method, using query -onmousedown leading to -onmousemove (drag) then -onmouseup (unbinds onmousemove)

the problem is, browser defaults begi

相关标签:
2条回答
  • 2021-02-09 07:03

    add css

    -webkit-touch-callout: none;/*for mobile*/
    -webkit-user-select: none;/*for chrome*/
    -khtml-user-select: none;/*for safari*/
    -moz-user-select: none;/*for Mozilla*/
    -ms-user-select: none;/*for mircosoft*/
    -o-user-select: none;/*for opera*/
    user-select: none;/*base css ,but not work in all browsers*/
    
    0 讨论(0)
  • 2021-02-09 07:14

    You could disable highlighting using css

    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -o-user-select: none;
    user-select: none;
    

    another way of doing this is to clear selection on drop event, as so:

    function clearSelection() {
        var sel;
        if(document.selection && document.selection.empty){
            document.selection.empty() ;
        } else if(window.getSelection) {
            sel = window.getSelection();
            if(sel && sel.removeAllRanges)
            sel.collapse();
        }
    }
    

    So you would call clearSelection() on drop event (after the drag is finished)

    0 讨论(0)
提交回复
热议问题