拖放,防止尴尬的高亮显示
drag and drop, prevent awkward highlighting?
我正在构建一个拖放方法,使用query-onmousedown导致-ommousemove(拖动),然后-ommouseup(取消绑定onmmousmove)
问题是,浏览器默认值开始突出显示onmousemove,它会在页面上飞得到处都是,并取消事件,使其无法使用。任何关于如何防止高亮显示的想法,因为preventDefault似乎都不起作用。这是我的代码(是的,非常草率,对不起!)
$(".middleRow").mousedown(function(){
calculateSelection();
$('body').append('<div class="messageDrag" style="display:block">'+numSelected+'<div style="font-size: 18px">messages</div></div>');
$(document).mouseup(function(){
$('.messageDrag').fadeOut(500);
setTimeout(function(){
$('.messageDrag').remove();
}, 500);
$(document).unbind();
})
$(document).mousemove(function(e){
e.preventDefault();
var x = e.pageX;
var y = e.pageY;
$(".messageDrag").css("left", x-49);
$(".messageDrag").css("top", 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();
}
}
因此,您可以在拖放事件(拖动完成后)调用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*/
相关文章:
- 从桌面读取python文件时高亮显示代码
- 高亮显示时编辑文本大小和颜色
- 高亮显示与数组字符串一起使用时文本插件中断
- FF视图源|脚本高亮显示为红色
- 父页面的角度路由器导航高亮显示
- OpenLayers在悬停时高亮显示功能,并在单击时选择
- 当DIV中的文本高亮显示时,如何获得DIV中Span的值?(Javascript)
- 延迟高亮显示文本区域中的文本
- Mootools:如何在点击时保持元素高亮显示并停止所有事件
- 高亮显示单击菜单链接
- Firefox-当不在输入控件上时隐藏焦点高亮显示
- 高亮显示包含<br>以及重新格式化网格
- 使用下拉选择菜单高亮显示一行表格单元格
- 如何限制javascript高亮显示函数的使用次数
- 在GXT中激活上下文菜单时,如何保持选中的文本高亮显示?(EXT GWT 2.x)
- html5中的文本高亮显示
- Markdown语法高亮显示未按预期工作
- D3js连续一个接一个地高亮显示条
- Javascript:搜索和高亮显示包括HTML标记
- 单击并用CTRL+C复制值时高亮显示html表格单元格