0
我有一个jQuery手机列表,它有一个滑动删除功能,并在本地存储首选项。我试图实现一个功能来重新排列列表项并将其存储在同一个数组中,请大家帮忙! 这里是我的小提琴:http://jsfiddle.net/f18nfz/nUSUB/2/可排序的jQuery移动列表;与本地存储
因此函数可能是这样的(http://jsfiddle.net/maziar/P2XDc/):
function moveUp(item) {
var prev = item.prev();
if (prev.length == 0)
return;
prev.css('z-index', 999).css('position','relative').animate({ top: item.height() }, 250);
item.css('z-index', 1000).css('position', 'relative').animate({ top: '-' + prev.height() }, 300, function() {
prev.css('z-index', '').css('top', '').css('position', '');
item.css('z-index', '').css('top', '').css('position', '');
item.insertBefore(prev);
});
}
function moveDown(item) {
var next = item.next();
if (next.length == 0)
return;
next.css('z-index', 999).css('position', 'relative').animate({ top: '-' + item.height() }, 250);
item.css('z-index', 1000).css('position', 'relative').animate({ top: next.height() }, 300, function() {
next.css('z-index', '').css('top', '').css('position', '');
item.css('z-index', '').css('top', '').css('position', '');
item.insertAfter(next);
});
}
$(".FieldContainer").sortable({ items: ".OrderingField", distance: 10 });
$('button').click(function() {
var btn = $(this);
var val = btn.val();
if (val == 'up')
moveUp(btn.parents('.OrderingField'));
else
moveDown(btn.parents('.OrderingField'));
});
由于我的列表很长,你需要滚动它,我想要的按钮,或者,如果我可以只有一个图标或每个列表项上的按钮拖动可以工作... – user2124239