0
我有這樣的功能:滑動UL列表元素水平
function smoothAdd(id, text)
{
var el = $('#' + id);
var h = el.height();
el.css({
height: h,
overflow: 'hidden'
});
var ulPaddingTop = parseInt(el.css('padding-top'));
var ulPaddingBottom = parseInt(el.css('padding-bottom'));
el.prepend('<li>' + text + '</li>');
var first = $('li:first', el);
var last = $('li:last', el);
var foh = first.outerHeight();
var heightDiff = foh - last.outerHeight();
var oldMarginTop = first.css('margin-top');
first.css({
marginTop: 0 - foh,
position: 'relative',
top: 0 - ulPaddingTop
});
last.css('position', 'relative');
el.animate({ height: h + heightDiff }, 1500)
first.animate({ top: 0 }, 250, function() {
first.animate({ marginTop: oldMarginTop }, 1000, function() {
last.animate({ top: ulPaddingBottom }, 250, function() {
last.remove();
el.css({
height: 'auto',
overflow: 'visible'
});
});
});
});
}
這需要在UL的ID,我想添加文本,將它添加幻燈片從頂部到底部的新元素後文。它也會刪除最後一個元素,每次添加一個新項目。我想使它水平工作,所以不是從頂部滑動,而是從右向左滑動,但不知道如何進行這種改變。
噓。出於測試目的顯示相關的HTML源代碼。 –
這是一個小提琴的例子。我覺得好像有更簡單的方法來做到這一點,所以將它留給其他人來解決 - http://jsfiddle.net/mrtsherman/ML7v5/ – mrtsherman