Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拖放,防止尴尬的突出显示?_Javascript_Jquery_Events_Drag And Drop - Fatal编程技术网

Javascript 拖放,防止尴尬的突出显示?

Javascript 拖放,防止尴尬的突出显示?,javascript,jquery,events,drag-and-drop,Javascript,Jquery,Events,Drag And Drop,我正在使用query构建一个拖放方法 -昂穆斯敦 导致-onmousemove(拖动)然后-onmouseup(解除绑定onmousemove) 问题是,浏览器默认设置开始在MouseMove上高亮显示,这会在整个页面上飞来飞去并取消事件,使其无法使用。任何关于如何防止突出显示的想法,因为preventDefault似乎都不起作用。这是我的代码(是的,很潦草,对不起!) $(“.middleRow”).mousedown(函数(){ 计算选择(); $('body')。追加(''+numSele

我正在使用query构建一个拖放方法 -昂穆斯敦 导致-onmousemove(拖动)然后-onmouseup(解除绑定onmousemove)

问题是,浏览器默认设置开始在MouseMove上高亮显示,这会在整个页面上飞来飞去并取消事件,使其无法使用。任何关于如何防止突出显示的想法,因为preventDefault似乎都不起作用。这是我的代码(是的,很潦草,对不起!)

$(“.middleRow”).mousedown(函数(){
计算选择();
$('body')。追加(''+numSelected+'messages');
$(文档).mouseup(函数(){
$('.messageDrag').fadeOut(500);
setTimeout(函数(){
$('.messageDrag').remove();
}, 500);
$(文档).unbind();
})
$(文档).mousemove(函数(e){
e、 预防默认值();
var x=e.pageX;
var y=e.pageY;
$(“.messageDrag”).css(“左”,x-49);
$(“.messageDrag”).css(“顶部”,y-49);
});
});

您可以使用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;
另一种方法是清除drop事件上的选择,如下所示:

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();
    }
}
因此,您可以在drop事件中调用
clearSelection()
(拖动完成后)

添加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*/

我不想完全删除高亮显示,只是在拖动状态下。但是我可以通过这样的查询来输入这个css,它是否有完整的浏览器支持?是的,它应该涵盖大多数现代浏览器(因此所有的供应商前缀,甚至ms),您可以执行
$(element.css({//css over})auto
,一旦拖放完成。嗯……这似乎不会阻止高亮显示,只是在视觉上消除它。更大的问题是突出显示的行为(当用户开始拖动文本时,会出现突出显示,或者在开始拖动文本时,会取消拖动并开始突出显示),这会破坏拖放。嗯,好的,明白了。。。让我找出我的答案,看看是否合适:)
-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*/