A simple approach is:
function ticker(el, duration) {
if (!el) {
return false;
}
else {
el = typeof el === 'object' ? el : $(el);
duration = duration || 500;
$(el).find('li').first().slideUp(duration, function() {
$(this)
.insertAfter($(this).nextAll('li').last())
.fadeIn(duration, function(){
ticker(el, duration);
});
});
}
}
You can call this with a jQuery object:
ticker($('#ticker'));
JS Fiddle demo.
Or using a plain DOM node, with a specified duration (in milliseconds):
ticker(document.getElementById('ticker'), 300);
JS Fiddle demo.
In response to the comment left by the OP (in comments, below):
This solution slides up the first item and fades in the last one. but I want fade+slide at both first and next items. the list is styled so just one item displayed at a time.
I offer this, using animate()
to animate the height/opacity of the list elements:
function ticker(el, duration) {
if (!el) {
return false;
}
else {
el = typeof el === 'object' ? el : $(el);
duration = duration || 500;
var first = el.find('li').first(),
last = first.nextAll().last(),
h = last.height();
first.animate({
height: 0,
opacity: 0
}, duration, function() {
$(this).insertAfter(last).animate({
height: h,
opacity: 1
}, duration, function() {
ticker(el, duration);
});
});
}
}
JS Fiddle demo.
Edited following clarification from OP, to the following:
function ticker(el, duration) {
if (!el) {
return false;
}
else {
el = typeof el === 'object' ? el : $(el);
duration = duration || 500;
var lis = el.find('li').css('display', 'none');
lis.first().fadeIn(duration, function(){
$(this).slideUp(duration, function(){
$(this).insertAfter(lis.last());
ticker(el, duration);
});
});
}
}
JS Fiddle demo.
References: