jquery sortable 的绝对定位“句柄”问题-在可排序元素范围之外时不影响排序

发布于 2024-09-15 20:23:10 字数 470 浏览 1 评论 0原文

我遇到了一个无法解决的问题。

我有一个类似 Basecamp 的项目列表,左侧有一个小菜单,其中有“拖动”、“编辑”和“垃圾箱”图标。

手柄就在那里。他位于可排序元素的范围之外,这就是为什么他根本不影响排序。

问题演示

正如你所看到的,我的拖动图标位于左侧。他不在 {LI} 范围内。 LI 在 char 结束的地方结束,因此 Handle 脱离了他的父级,不会影响所有排序,也不会启动它。

当我拖动它并将鼠标移动到 LI 的边界内时,它会像预期的那样影响和排序。

我能做些什么。我绞尽脑汁寻找句柄偏移的属性,或者任何为他定义我的句柄超出你的范围的方法。

我希望任何人过去遇到过这件事并且可能会有所帮助:) 我想放一个子弹图像背景,这样可以给 LI 左边更多的空间。 可能会成功...:)

谢谢

I got a problem I cannot manage to resolve.

I have a Basecamp alike list of items with a small menu on the left with Drag, Edit and Trash icons.

The handle is there. He is sitting outside of the scope of the sortable element, and this is why he doesn't influence the sorting at all.

The problem demonstration

As you can see, my dragging icon is on the left. He is outside of the {LI} scope. The LIs endings where the char ends, so the Handle is out from his parent and wont influence at all the sorting and wont initiate it.

When I drag it but move my mouse inside the LI's borders, than it influencing and sorting like it suppose to.

What can I do. I broke my head and searched for an property of an handle offset, or any way to define for him that my handle is outside of your scope.

I hope anyone faced this thing in the past and might help :)
I think to put a bullet image bg, and this way to give the LI more space to its left.
Might do the trick... :)

Thank you

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

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

发布评论

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

评论(2

陪你搞怪i 2024-09-22 20:23:11

我可以通过覆盖确定光标是否位于元素上方的方法来解决此问题。由于我的列表与您的列表一样是垂直的,因此我撕掉了水平位置的检查,以便它只检查垂直位置。这样,光标水平位置在哪里并不重要。

只需将其放在主 jquery.ui.js 包含之后和可排序代码之前即可覆盖该方法:

// UI Fix for draggable
$.extend($['ui']['sortable'].prototype, {
    _intersectsWithPointer: function(item) {

        var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
            verticalDirection = this._getDragVerticalDirection(),
            horizontalDirection = this._getDragHorizontalDirection();

        if (!isOverElementHeight)
            return false;

        return this.floating ?
            ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
            : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) );

    }
});

显然,这会破坏水平排序的功能,因此您只想将其包含在特殊情况下。

亲爱的 jQuery UI 团队:请求使用选项来处理此问题的功能。 :)

萨米克

I was able to fix this by overwriting the method that determines if the cursor is over the element or not. Since my list was vertical like yours, I ripped out the checks for the horizontal position so that it only checks the vertical position. That way it doesn't matter where the cursor is horizontally.

Just put this after your main jquery.ui.js include and before your sortable code to overwrite the method:

// UI Fix for draggable
$.extend($['ui']['sortable'].prototype, {
    _intersectsWithPointer: function(item) {

        var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
            verticalDirection = this._getDragVerticalDirection(),
            horizontalDirection = this._getDragHorizontalDirection();

        if (!isOverElementHeight)
            return false;

        return this.floating ?
            ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
            : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) );

    }
});

Obviously this breaks functionality for horizontal sorting, so you'll only want to include it in your special case.

Dear jQuery UI Team: Call for feature to handle this using an option. :)

SammyK

彩扇题诗 2024-09-22 20:23:11

我也有同样的问题。

我注意到这里提交了一个未解决的错误: http://bugs.jqueryui.com/ticket /3022#comment:9

以及声称解决该问题的拉取请求: https://github.com/jquery/jquery-ui/pull/915

这么多年了还没有修复,有点蛋疼。

不管怎样,我正在考虑像 SammyK 建议的那样进行更改,但后来注意到 v1.10.3 中有一个 axis 选项。我不确定这是否存在于以前的 jQuery UI 版本中。

但是设置 axis 为我解决了这个问题:

$('.items').sortable({
  containment:'parent',
  handle:'.move',
  opacity:0.5,
  axis:'y'
});

我的手柄现在可以位于可拖动项目之外,但仍然能够正确地上下拖动项目。

I had this same issue.

I noticed there is a open bug submitted here: http://bugs.jqueryui.com/ticket/3022#comment:9

As well as a pull request that claims to fix the issue: https://github.com/jquery/jquery-ui/pull/915

It's a bit of a pain that it still hasn't been fixed yet after all these years.

Anyway, I was considering making a change like SammyK suggests, but then noticed that there is a axis option in v1.10.3. I'm not sure if this existed in previous jQuery UI releases.

But setting axis fixes the issue for me:

$('.items').sortable({
  containment:'parent',
  handle:'.move',
  opacity:0.5,
  axis:'y'
});

My handle can now reside outside of my draggable items, but still be able to drag the items up and down correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文