将 Draggable 连接到 Sortable 会导致辅助元素跳转

发布于 2024-11-04 13:32:29 字数 2060 浏览 7 评论 0原文

我在页面上有一个 jQueryUI 可拖动对象和一个可排序对象。

将元素从可拖动元素拖动到可排序元素会导致拖动的元素跳至页面左上角

这是演示: http://jsfiddle.net/travisrussi/aBhDu/1/

重现:

  • 将“Item 5”从可拖动div(顶部框)拖动到可排序div(底部框)

实际结果:


看起来拖动的元素从相对定位切换到绝对定位。 拖动的“li”从: 切换为

<li class="ui-state-default ui-draggable" style="position: relative; left: 52px; top: 9px;">Item 3</li>

: 。

<li class="ui-state-default ui-draggable ui-sortable-helper" style="position: absolute; left: 67px; top: 91px; width: 80px; height: 20px;">Item 3</li>

当可拖动项目被拖动到可排序对象中时,


这是 jQueryUI 1.8.12 的相关片段(从第 3041 行开始):

//The element's absolute position on the page minus margins
this.offset = this.currentItem.offset();
this.offset = {
    top: this.offset.top - this.margins.top,
    left: this.offset.left - this.margins.left
};

// Only after we got the offset, we can change the helper's position to absolute
// TODO: Still need to figure out a way to make relative sorting possible
this.helper.css("position", "absolute");
this.cssPosition = this.helper.css("position");

$.extend(this.offset, {
    click: { //Where the click happened, relative to the element
        left: event.pageX - this.offset.left,
        top: event.pageY - this.offset.top
    },
    parent: this._getParentOffset(),
    relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
});

//Generate the original position
this.originalPosition = this._generatePosition(event);
this.originalPageX = event.pageX;
this.originalPageY = event.pageY;

是否有一些我没有使用的配置选项?

CSS有问题吗?

或者这是 jqueryUI 中的一个错误?

I have a jQueryUI draggable object and a sortable object on the page.

Dragging an element from the draggable to the sortable causes the dragged element to jump up to the top left of the page.

Here's the demo: http://jsfiddle.net/travisrussi/aBhDu/1/

To reproduce:

  • Drag 'Item 5' from the draggable div (top box) to the sortable div (bottom box)

Actual result:


It appears the dragged element switches from relative to absolute positioning. The dragged 'li' switches from:

<li class="ui-state-default ui-draggable" style="position: relative; left: 52px; top: 9px;">Item 3</li>

to this:

<li class="ui-state-default ui-draggable ui-sortable-helper" style="position: absolute; left: 67px; top: 91px; width: 80px; height: 20px;">Item 3</li>

when the draggable item is dragged into the sortable object.


This is the relevant snippet from jQueryUI 1.8.12 (starts at line 3041):

//The element's absolute position on the page minus margins
this.offset = this.currentItem.offset();
this.offset = {
    top: this.offset.top - this.margins.top,
    left: this.offset.left - this.margins.left
};

// Only after we got the offset, we can change the helper's position to absolute
// TODO: Still need to figure out a way to make relative sorting possible
this.helper.css("position", "absolute");
this.cssPosition = this.helper.css("position");

$.extend(this.offset, {
    click: { //Where the click happened, relative to the element
        left: event.pageX - this.offset.left,
        top: event.pageY - this.offset.top
    },
    parent: this._getParentOffset(),
    relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
});

//Generate the original position
this.originalPosition = this._generatePosition(event);
this.originalPageX = event.pageX;
this.originalPageY = event.pageY;

Is there some configuration option I'm not using?

Is there an issue with the CSS?

Or is this a bug in jqueryUI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花ソ最美的依靠 2024-11-11 13:32:29

跳转的主要原因是可拖动对象的“助手”选项未设置为“克隆”。如果您使用克隆助手,跳跃问题就会消失。

如果您需要使用“原始”辅助设置,您仍然会遇到跳跃问题。一种可能的解决方案是使用自定义帮助器选项,如下所示:jQueryUI Draggable Helper Option Help。这个想法是在创建助手时将相对位置转换为绝对位置。

以下是使用“克隆”助手的工作演示的链接: http://jsfiddle.net/travisrussi/aBhDu /

The primary cause of the jump was that the 'helper' option of the draggable was not set to 'clone'. If you use a clone helper, the jumping problem goes away.

If you need to use the 'original' helper setting, you will still have the jumping issue. One possible solution for it could be to use a custom helper option, as highlighted here: jQueryUI Draggable Helper Option Help. The idea would be to convert the position from relative to absolute at the time the helper is created.

Here's a link to the working demo using a 'clone' helper: http://jsfiddle.net/travisrussi/aBhDu/

孤者何惧 2024-11-11 13:32:29

似乎自定义辅助函数解决了这个问题,如下所示:

        $( ".draggable" ).draggable({
            connectToSortable: "#sortable",
            //helper: "original",
            revert: "invalid",
            helper: function() {
                return $(this);
            }
        });

It seems a custom helper function solves this problem, like this:

        $( ".draggable" ).draggable({
            connectToSortable: "#sortable",
            //helper: "original",
            revert: "invalid",
            helper: function() {
                return $(this);
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文