我使用以下 javascript(带有 jQuery)来处理我正在编写的脚本上的拖放:
jsc.ui.dragging = false;
jsc.ui.drag_element = {};
$(".drag-target").mousedown(function() {
jsc.ui.drag_element = $(this);
jsc.ui.dragging = true;
});
$("html").mousemove(function(e) {
if(jsc.ui.dragging) {
jsc.ui.drag_element.css({"position": "absolute", "top": e.clientY - 1, "left": e.clientX - 1, "z-index": "100"}); // - 1s are due to IE not leaving go otherwise
$("#overlay").show(); // Overlay stops text beneath being selected. TODO Stop current elements text being selected.
}
});
$(".drag-target").mouseup(function() {
if(jsc.ui.dragging) {
jsc.ui.dragging = false;
jsc.ui.drag_element.css("z-index", "98");
$("#overlay").hide();
}
});
但是,当拖动对象时,其内部的文本会出现闪烁的选择,即随着元素的移动,它会被选中和关闭。有什么办法可以防止这种情况,或者隐藏它的影响吗?
最佳答案
有没有理由不使用jQuery UI Draggable ?您的代码将如下所示:
$(".drag-target").draggable();
你至少应该检查一下它是如何构建的,它可能会帮助你解决闪烁问题。
关于javascript - 如何通过javascript拖放避免闪烁效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/663661/