javascript - JqueryUI 拖动 : Cursor not at the same position as draggable element

标签 javascript jquery css jquery-ui jquery-ui-draggable

我正在使用最新版本的 JQuery 和 JQuery UI 来了解拖放功能。我遇到了一个小问题 - 主要是由于鼠标拖动。

As you can see that I am creating stacks with some items in it.

Now if these stacks are just inside body - I mean div.allstacks is in body there is no problem. But as soon as I put all these stacks inside a div#left-panel, the problem of cursor losing focus starts.

This means now when I drag an item, after horizontal scroll - My mouse cursor is not at the same position of draggable note.

问题来了:

Screenshot of the problem

JSFiddle 链接 [在没有 div 的情况下工作#left-panel]: http://jsfiddle.net/deveshz/YvmFf/

JSFiddle 链接 [不适用于 div#left-panel] http://jsfiddle.net/deveshz/YvmFf/1/


这是代码。

Javascript:

var zindex = 10; 
$(".item").draggable({
    containment: "body",
    scroll: true,
    revert: function (event, ui) {
        $(this).css("border", "none");
        return !event;
   },
    start: function (event, ui) {
        $(this).css("z-index", zindex++);
        $(this).css("border", "2px solid #333");
    }
});

 $(".stack_items").droppable({
    hoverClass: "over",
    drop: function (event, ui) {
        $("<li class='item'></li>").html(ui.draggable.html()).appendTo(this);
        $(ui.draggable).remove();
    }
});

最佳答案

当我尝试阅读@konrad 提供的链接时,我发现它是 Jquery UI 中的一个错误——即使是在它的最新版本中也是如此。我一开始使用Jquery UI 1.9.2版本问题就解决了

这是更新后的 fiddle :http://jsfiddle.net/deveshz/YvmFf/2/

使用相同的代码:

var zindex = 10; 
$(".item").draggable({
    containment: "body",
    scroll: true,
    revert: function (event, ui) {
        $(this).css("border", "none");
        return !event;
   },
    start: function (event, ui) {
        $(this).css("z-index", zindex++);
        $(this).css("border", "2px solid #333");
    }
});

 $(".stack_items").droppable({
    hoverClass: "over",
    drop: function (event, ui) {
        $("<li class='item'></li>").html(ui.draggable.html()).appendTo(this);
        $(ui.draggable).remove();
    }
});

它使用来自 http://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js 的 Jquery 版本 1.9.2|

关于javascript - JqueryUI 拖动 : Cursor not at the same position as draggable element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19462462/

相关文章:

javascript - 退出时清除剪贴板

javascript - 我想验证所选日期和时间何时超过当前日期和时间

javascript - js文件加载顺序

jquery - Bootstrap 汉堡包菜单 Jquery

css - 不同大小的 float div

javascript - 将 jScrollPane JQuery 插件与 RequireJS 一起使用

javascript - 定位 iframe 并同时显示文本?

jquery - 将鼠标悬停在同一位置的两个元素上

javascript - 使用 jQuery 打开链接并自动滚动到特定的 div

javascript - css,jquery调整可拖动div之间的线