Mặc dù câu trả lời bằng cách Azatoth hoạt động tốt, bobby có thể tìm kiếm một hình ảnh động, giống như tôi đã làm. vì vậy tôi đã viết đoạn mã sau để làm cho phong trào hoạt hình:
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);
});
}
bạn có thể có một cái nhìn ở đây http://jsfiddle.net/maziar/P2XDc/
Nguồn
2013-05-16 08:41:39
Câu trả lời thứ hai là tuyệt vời. Câu trả lời đầu tiên cũng tốt. Tại sao bạn không chấp nhận? –