script.aculo.us 可使用分隔符排序

发布于 2024-11-29 03:05:39 字数 695 浏览 3 评论 0原文

我想使用 Script.aculo.us Sortable 对水平列表的元素进行排序(比如说一些小盒子)。问题在于,这些盒子必须由另一个不同类型的盒子相互隔开,这些盒子不应该是可移动的,但它们必须始终位于这些可分类盒子之间,每对可移动盒子之间有一个。

让我们用 [M] 标记可移动框,用 [D] 标记不可移动分隔符。那么情况如下:

[M1][D][M2][D][M3][D][M4]

现在,当用户将例如[M2]可移动框拖动到[M4]位置时,情况应该变成:如下:

[M1][D][M3][D][M4][D][M2]

当他将[M4]可移动框移动到[M2]位置时,情况应如下所示:

[M1][D][M3][D][M4][D][M2]

但禁止进行以下设置:

[M1][D][M3][M4][D][D][M2]
[M1][D][M4][D][M2][M3][D]

即任何两个分隔符都不能彼此靠近,并且没有分隔符应留在序列的前面或末尾。

我如何使用 Script.aculo.us Sortables 制作类似的东西?有可能吗?

I'd like to use Script.aculo.us Sortable to sort elements of a horizontal list (let's say some little boxes). The problem is that these boxes have to be separated from each other by another boxes of a different kind, which shouldn't be movable, but they have to be always there in between these sortable boxes, one between each pair of movable boxes.

Let's mark movable boxes by [M] and unmovable delimiters by [D]. Then the situation is as follows:

[M1][D][M2][D][M3][D][M4]

Now, when a user drags, for example, the [M2] movable box to the position of [M4], the situation should become as follows:

[M1][D][M3][D][M4][D][M2]

and when he moves the [M4] movable box into the [M2] position, the situation should be like below:

[M1][D][M3][D][M4][D][M2]

But the following settings are forbidden:

[M1][D][M3][M4][D][D][M2]
[M1][D][M4][D][M2][M3][D]

that is, no two delimiters should be near each other, and no delimiter should be left in front or at the end of the sequence.

How can I make something like that using Script.aculo.us Sortables? Is it possible at all?

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

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

发布评论

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

评论(1

浪荡不羁 2024-12-06 03:05:39

我想我已经找到了一种方法:它可以通过 CSS 规则来完成。
我只需为列表元素设置以下规则:

li:before {
  content: "[D]";   /* my delimiter */
}

li:first-child:before {
  content: "";
}

这使得所有列表元素(但首先)在其容器中的前面都附加有 [D] 文本。

现在,当我在列表项(SortableDraggable)中移动时,CSS 会更新这些分隔符:当我将一个元素拖动到列表的开头时,它会更新这些分隔符。获得 :fisrt-child 伪类,因此它显示时没有分隔符。在列表中的任何其他位置,它都缺少这个伪类,因此分隔符出现在它的前面。

所以看起来问题已经解决了。

I think I've figured a way to make it: It could be done by CSS rules.
I simply set the following rule for my list element:

li:before {
  content: "[D]";   /* my delimiter */
}

li:first-child:before {
  content: "";
}

This makes that all list elements but first will have [D] text attached before them in their container.

Now when I move around my list items (Draggables of a Sortable), the CSS keeps these delimiters updated: when I drag an element to the beginning of the list, it gains :fisrt-child pseudo-class, so it appears without the delimiter. At any other place in the list it lacks this pseudo-class, so the delimiter appears in front of it.

So looks like the problem is solved.

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