jQuery 可排序 - 连接问题
我在 jsFiddle 上有两个示例:
示例 1
在第一个中,我可以移动列表元素,甚至从子元素到根元素。然而,要让它“啪”的一声,却并不是一件容易的事。
示例 2
在第二个示例中,我浮动了列表元素。这次我无法让它们“捕捉”到子元素。
问题
- 有没有什么好方法可以让拍摄变得更容易?
- 怎么用float来解决呢?
I have two examples on jsFiddle:
Example 1
In the first one I can move the list elements around, even from a child element to the root element. However, it's not very easy to make it "snap".
Example 2
In the second example I have floated the list elements. This time I can't get them to "snap" to the child elements.
Questions
- Is there a good way to make it easier to snap?
- How do I solve it with float?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery sortable 中有一个迄今为止未记录的选项来定义检查容差的元素:
toleranceElement
。如果未设置,则会检查整个项目的位置(包括嵌套列表),但如果设置了,则仅考虑与选择器匹配的子项目。这意味着您必须稍微更改 HTML 标记,以将列表项的主要内容(在您的情况下为项目文本)包装在元素中,并使用它来检查排序位置。这将省略嵌套的
,有效地阻止抖动,否则会非常严重。
HTML:
Javascript:
尝试修改后的演示此处和此处。
您可能还想使用
opacity
、cursorAt
和tolerance
。查看文档。请注意,这不是一个完美的解决方案,如果您对结果不满意,请考虑使用插件。 Manuele J Sarfatti 的
nestedSortable
插件看起来可能对您有用:http:// /mjsarfatti.com/sandbox/nestedSortable/There is a so far undocumented option in jQuery sortable to define the element against which tolerance is checked:
toleranceElement
. If not set, the whole item is checked for placement (including the nested list), but if it's set, only sub-items matching the selector are taken into account.This means you have to change your HTML markup a bit to wrap the main content of the list item (the item text in your case) in an element and use that to check for sort positioning. That will leave out the nested
<ul>
s, effectively stopping jittering which is otherwise quite serious.HTML:
Javascript:
Try your modified demos here and here.
You might also want to play with
opacity
,cursorAt
andtolerance
. Have a look at the documentation.Note that it's not a perfect solution, in case you're not satisfied with the results, have a look at using a plugin. Manuele J Sarfatti's
nestedSortable
plugin looks like something that might be of use for you: http://mjsarfatti.com/sandbox/nestedSortable/我正在 Safari 中查看您的两个示例,并且我能够将任何元素移入/移出子元素,而不会出现大问题。
这就是为什么 #2 更难使用的原因...
示例 #2 中的“放置区域”仅与您的元素一样高,因此对于较短的元素,可以让鼠标进入的区域要小得多。
示例 #1 中的“放置区域”非常宽,因此当您在列表中上下移动鼠标时很容易点击它。
我能想到的解决你的问题的唯一方法就是简单地让示例#2 中的项目更高,从而模拟示例#1 中除了侧面之外的项目。
http://jsfiddle.net/9uhfX/3/
I'm looking at both of your examples in Safari and I am able to move any element in/out of the children elements without a huge problem.
Here is why #2 is more difficult to use...
The "drop zone" in example #2 is only as high as your element so with your short elements, there is a much smaller area to get your mouse into.
The "drop zone" in example #1 is very wide so it's very easy to hit it as you move your mouse up/down the list.
The only way I can think of to solve your problem is to simply make your items in example #2 taller, thereby simulating what you have in example #1 except on its side.
http://jsfiddle.net/9uhfX/3/