Jquery Sortable 获取底层 div 的 ID

发布于 2024-10-09 00:20:03 字数 1448 浏览 0 评论 0原文

我正在使用 jquery 可排序功能对应用程序中的项目列表进行排序。看到我的列表变得相当大,我决定将它们重新组织为可以展开或折叠的子列表。

我的想法是,当用户将一个元素拖动到子列表的标题上并将光标保持在那里 750 毫秒时,列表会展开,但我遇到了一个问题,我无法获取底层 div 的 ID,因为jquery 似乎抓取了我正在拖动的项目的 ID,而不是我让它悬停的项目的 ID。

有没有我可以用来实现此目的的功能或插件(我确信我不是第一个遇到此问题的人,但我的 googlefu 未能找到与我相关的任何内容)。

感谢您的帮助:)

编辑:

这是我想做的事情的一个想法:

$('.categoryLi').hover(function(){expandCategory(this.id);});

function expandCategory(id)
{
    if(sectionDraggingMode)
    {   
        $(document).oneTime('750ms', 'expandCategoryTimer', function(){$('#'+id+' .category_content').show();});
    }
}

这是我的 HTML 的要点:

<ul class="category">
    <li class="categoryLi" id="c8">
            <div class="sublistHeader"></div>
            <div id="cat_8_container" class="category_content" style="display: none;">
            //sortable list here
            </div>
    </li>
    <li class="categoryLi" id="c9">
            <div class="sublistHeader"></div>
            <div id="cat_9_container" class="category_content" style="display: none;">
            //other sortable list here
            </div>
    </li>
</ul>

现在当我将鼠标悬停在 .categoryLi 上时,我调用 ExpandCategory 发送在我悬停的元素的 id 上,但它永远不会触发任何 .categoryLi 容器的悬停,除了我目前正在拖动的元素的父级之外。我需要找到一种方法来“窥视”它的背后。因此,如果我从 #c9 拖动一个项目,jquery 会认为我总是悬停在 #c9

I'm using the jquery sortable functionality to sort a list of items in my application. Seeing how my lists were getting pretty large I decided to reorganize them in sublists that can be expanded or collapsed.

The idea I had was that when the user drags an element over the header of a sublist and holds his cursor there for 750ms the list expands but I've run into a problem where I can't get the ID of the underlying div's ID because jquery seems to grab the ID of the item I'm dragging and not what I'm making it hover over.

Is there a functionality or plugin I can use to achieve this (I'm sure I'm not the first to have this problem but my googlefu has failed to turn up anything that's relevant to me).

Thanks for any help :)

Edit:

Here's an idea of what I'm trying to do:

$('.categoryLi').hover(function(){expandCategory(this.id);});

function expandCategory(id)
{
    if(sectionDraggingMode)
    {   
        $(document).oneTime('750ms', 'expandCategoryTimer', function(){$('#'+id+' .category_content').show();});
    }
}

And here's the gist of my HTML:

<ul class="category">
    <li class="categoryLi" id="c8">
            <div class="sublistHeader"></div>
            <div id="cat_8_container" class="category_content" style="display: none;">
            //sortable list here
            </div>
    </li>
    <li class="categoryLi" id="c9">
            <div class="sublistHeader"></div>
            <div id="cat_9_container" class="category_content" style="display: none;">
            //other sortable list here
            </div>
    </li>
</ul>

The way it is now when I hover over .categoryLi I call expandCategory sending over the id of the element I'm hovering over but it never triggers the hover of any .categoryLi container except for the parent of the element I'm dragging at the moment. I need to find a way to "peek" behind it. So if I'm dragging an item from #c9 jquery thinks I'm always hovering over #c9

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

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

发布评论

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

评论(1

拔了角的鹿 2024-10-16 00:20:03

事实证明,jquery 的 droppable 可以用于此目的。我将要用作展开触发器的区域定义为可放置区域,并在触发 over 事件时执行此操作。

$('.categoryLi > .toolbar').droppable({
    accept: ".sectionLi",
    over: function(event, ui){
        $(this).siblings('.category_content').show();
        $('.section').sortable('refreshPositions');
    }
});

此修复存在一些问题,但至少解决了悬停问题。希望这可以帮助将来的人。

Well turns out that jquery's droppable can be used for this. I defined the area that I want to use as a trigger to the expand as a droppable area and did just that when the over event is triggered.

$('.categoryLi > .toolbar').droppable({
    accept: ".sectionLi",
    over: function(event, ui){
        $(this).siblings('.category_content').show();
        $('.section').sortable('refreshPositions');
    }
});

There are some problems with this fix but at least it solved the issue with the hovers. Hope this can help someone in the future.

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