jquery 可排序、浮动和清除

发布于 2024-11-29 07:49:10 字数 628 浏览 2 评论 0原文

所以我在这里有一个我想要做的快速模型 - http://antimac。 meloncreative.co.uk/labs/nth.php

实时版本是使用 div 内的缩略图完成的,这些缩略图具有不同的宽高比。因此宽度始终为 100px,但高度可以是任何值(或多或少)。

无论如何,正因为如此,并且使用浮动,有时它们不能很好地融入一条线上的 5 条线上,有些低于其他线,所以它们或多或少都在自己的线上,这使得它看起来很混乱。

那么...在排序和更新时如何做到这一点,clears总是能很好地使每行5个div?目前我正在做的事情

$('#reorder div.x:nth-child(5n)').addClass('clear green');

...并没有像我希望的那样工作

编辑:所以我认为问题出在 (5n) 部分,就像当我将第 1 项拖动到 5 和6、在拖动过程中,第一行缺少 2 个块,然后当我放下它时,第一行缺少 1 个块。这可能与我所拖动的克隆仍然在那里影响结果、想法有关?

So I have a quick mockup here of what I am trying to do - http://antimac.meloncreative.co.uk/labs/nth.php

The live version is done using thumbnails inside the divs, and these thumbnails are of various aspect ratios. So the width is always 100px, but the height can be whatever (more or less).

Anyways, because of this, and using float, sometimes they dont nicely fit into 5 on a line, with some going below others so they are more or less on their own line, which makes it look a mess.

So... how do I make it when sorting, and when updated, the clears will always nicely make 5 divs per row? Currently the bit where I am doing

$('#reorder div.x:nth-child(5n)').addClass('clear green');

... isnt working as I'd hoped

Edit: So I think the problem lies in the (5n) part, as when I drag say item 1, between 5 and 6, during the drag there are 2 blocks missing from the first row, then when I drop it, there is 1 missing from the first row. This possibly has something to do with the clone of the one I am dragging still being there slewing the results, ideas?

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

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

发布评论

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

评论(2

倾`听者〃 2024-12-06 07:49:10

我认为这还可以。只需确保在 x div 重新排序后添加绿色类即可。看看这个小提琴。 :eq 无法识别 n,请使用 :nth-child。

$('#reorder').children('div.x:nth-child(5n + 1)').addClass('clear green');

I think this is okay. just make sure adding class green after x divs have reordered. Look this fiddle. :eq doesn't recognize n, use :nth-child.

$('#reorder').children('div.x:nth-child(5n + 1)').addClass('clear green');
孤者何惧 2024-12-06 07:49:10

所以答案似乎是

$('#reorder').sortable({
        placeholder: 'placeholder',
        sort: function(event, ui) {
            $('#reorder div').removeClass('clear green');
            $('#reorder div.x:not(.ui-sortable-helper)').addClass('y');
            $('#reorder div.placeholder').addClass('y');
            $('#reorder div.y:nth-child(5n + 1)').addClass('clear green');
        },
        update: function(event, ui) {
            $('#reorder div.x').removeClass('y');
            $('#reorder div.x').removeClass('clear green');
            $('#reorder div.x:nth-child(5n + 1)').addClass('clear green');
        }
    });
    $('.reorder').disableSelection();
});

占位符和助手仍然存在问题,因为被拖动的内容仍然存在。

So the answer seemed to be

$('#reorder').sortable({
        placeholder: 'placeholder',
        sort: function(event, ui) {
            $('#reorder div').removeClass('clear green');
            $('#reorder div.x:not(.ui-sortable-helper)').addClass('y');
            $('#reorder div.placeholder').addClass('y');
            $('#reorder div.y:nth-child(5n + 1)').addClass('clear green');
        },
        update: function(event, ui) {
            $('#reorder div.x').removeClass('y');
            $('#reorder div.x').removeClass('clear green');
            $('#reorder div.x:nth-child(5n + 1)').addClass('clear green');
        }
    });
    $('.reorder').disableSelection();
});

It was having issues with placeholders and also the helper that was still in place from what was being dragged around.

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