jQuery 可排序和 CSS 问题
我在使用 jQuery 的可排序功能时遇到问题。我想要一个包含一行或多行的块。每行都有一个或多个链接。
我的 HTML
<div id="links">
<div class="line"><div class="link">Link #1</div></div>
<div class="line">
<div class="link">Link #2</div>
<div class="link">Link #3</div>
</div>
<div class="line"><div class="link">Link #4</div></div>
<div class="line"><div class="link">Link #5</div></div>
<div class="line"><div class="link">Link #6</div></div>
<div class="line">
<div class="link">Link #7</div>
<div class="link">Link #8</div>
</div>
</div>
我知道如何垂直排序行。我知道如何对同一行上的链接进行排序。但是,当我尝试对链接进行排序时,无论其行如何,它都会变得复杂。
将链接移动到另一行相对容易。只需检查它是否留下空行,如果是,则将其从 DOM 中删除。但是在两行之间添加链接(因此添加新行)是我遇到困难的地方。
感谢所有帮助。
Erik
我的 JavaScript:
$('#links .line').sortable({
connectWith: '.line',
forcePlaceholderSize: true,
placeholder: 'droppable',
tolerance: 'intersect',
revert: true,
update: function(event, ui) {
$('.line').each(function(){
if ($(this).html().trim() == '')
{
$(this).remove();
}
});
$('.link').each(function(){
if ($(this).parent().attr('class').indexOf('line') == -1)
{
$(this).wrap('<div class="line" />');
}
});
}
});
和我的 CSS:
#links
{
margin:0 0 45px 0;
}
#links .line
{
overflow:hidden;
height:auto;
clear:left;
width:490px;
margin:0 0 10px 0;
}
#links .line .link
{
overflow:hidden;
height:auto;
float:left;
background-color:#e5e5e5;
cursor:move;
padding:2px;
margin:0 10px 0 0;
}
#links .droppable
{
float:left;
height:16px;
padding:2px;
border:1px dashed #999;
margin:0 10px 0 0;
}
I'm having trouble with jQuery's sortable function. I'd like to have a block with one or more lines. And on each line is one or more links.
My HTML
<div id="links">
<div class="line"><div class="link">Link #1</div></div>
<div class="line">
<div class="link">Link #2</div>
<div class="link">Link #3</div>
</div>
<div class="line"><div class="link">Link #4</div></div>
<div class="line"><div class="link">Link #5</div></div>
<div class="line"><div class="link">Link #6</div></div>
<div class="line">
<div class="link">Link #7</div>
<div class="link">Link #8</div>
</div>
</div>
I know how to sort the lines vertically. And I know how to sort the links on the same line. But when I try to sort links regardless of the line it gets complicated.
Moving a link to another line is relatively easy. Just check if it leaves an empty line, if so remove it from the DOM. But adding a link between two lines (and so adding a new line) is where I get stuck.
All help is appreciated.
Erik
My JavaScript:
$('#links .line').sortable({
connectWith: '.line',
forcePlaceholderSize: true,
placeholder: 'droppable',
tolerance: 'intersect',
revert: true,
update: function(event, ui) {
$('.line').each(function(){
if ($(this).html().trim() == '')
{
$(this).remove();
}
});
$('.link').each(function(){
if ($(this).parent().attr('class').indexOf('line') == -1)
{
$(this).wrap('<div class="line" />');
}
});
}
});
And my CSS:
#links
{
margin:0 0 45px 0;
}
#links .line
{
overflow:hidden;
height:auto;
clear:left;
width:490px;
margin:0 0 10px 0;
}
#links .line .link
{
overflow:hidden;
height:auto;
float:left;
background-color:#e5e5e5;
cursor:move;
padding:2px;
margin:0 10px 0 0;
}
#links .droppable
{
float:left;
height:16px;
padding:2px;
border:1px dashed #999;
margin:0 10px 0 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论