简体   繁体   English

JqueryUI Drag:Cursor与draggable元素不在同一位置

[英]JqueryUI Drag: Cursor not at the same position as draggable element

I am using the latest version of JQuery and JQuery UI to understand drag and drop features. 我正在使用最新版本的JQuery和JQuery UI来理解拖放功能。 I am facing a minor problem - mostly due to mouse drag. 我面临一个小问题 - 主要是由于鼠标阻力。

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. 现在,如果这些堆栈只是在体内 - 我的意思是div.allstacks在体内是没有问题的。 But as soon as I put all these stacks inside a div#left-panel, the problem of cursor losing focus starts. 但是一旦我将所有这些堆栈放在div#left-panel中,光标失去焦点的问题就开始了。

This means now when I drag an item, after horizontal scroll - My mouse cursor is not at the same position of draggable note. 这意味着现在当我拖动项目时,水平滚动后 - 我的鼠标光标不在可拖动音符的相同位置。

Now here is the problem: 现在问题是:

问题的屏幕截图

JSFiddle Link [Working without div#left-panel]: http://jsfiddle.net/deveshz/YvmFf/ JSFiddle Link [无div工作#左侧面板]: http//jsfiddle.net/deveshz/YvmFf/

JSFiddle Link [NOT Working with div#left-panel] http://jsfiddle.net/deveshz/YvmFf/1/ JSFiddle Link [不使用div#left-panel] http://jsfiddle.net/deveshz/YvmFf/1/


Here is the code. 这是代码。

Javascript: 使用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();
    }
});

As I tried out and read through the link given by @konrad, I found that its a bug in Jquery UI - even in the latest version of it. 当我尝试并阅读@konrad提供的链接时,我发现它是Jquery UI中的一个错误 - 即使在最新版本中也是如此。 The problem got solved as soon as I started using Jquery UI 1.9.2 version 一旦我开始使用Jquery UI 1.9.2版本,问题就解决了

here is the updated fiddle: http://jsfiddle.net/deveshz/YvmFf/2/ 这是更新的小提琴: http//jsfiddle.net/deveshz/YvmFf/2/

with same code: 使用相同的代码:

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();
    }
});

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM