Reputation: 398
My javascript is not up to scratch at the moment and I am stumped with this!
I need to create an animated list with javascript like this one - http://www.fiveminuteargument.com/blog/scrolling-list.
What I want is to take a list like so
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
</ul>
And display two at once, then display them in a loop, 2 at a time.
Even pseudo code would help to get me started.
Upvotes: 5
Views: 259
Reputation: 3294
Just a modification to Yuval's code, to get the 'two at a time' behaviour working:
$(document).ready(function(){
//hide all the list items
$("ul li").hide();
//call the function initially
show_list_item();
});
function show_list_item(){
//fade in the first hidden item. When done, run the following function
$("ul li:hidden:first").fadeIn("slow", function(){
//if there are no more hidden list items (all were shown), hide them all
if($("ul li:hidden").length == 0){
$("ul li").hide();
}
});
$("ul li:hidden:first").fadeIn("slow", function(){
//if there are no more hidden list items (all were shown), hide them all
if($("ul li:hidden").length == 0){
$("ul li").hide();
}
//call this function again - this will run in a continuous loop
show_list_item();
});
}
Upvotes: 0
Reputation: 26713
With the html you included in your message, you can run the following.
$(document).ready(function(){
//hide all the list items
$("ul li").hide();
//call the function initially
show_list_item();
});
function show_list_item(){
//fade in the first hidden item. When done, run the following function
$("ul li:hidden").first().fadeIn("slow", function(){
//if there are no more hidden list items (all were shown), hide them all
if($("ul li:hidden").length == 0){
$("ul li").hide();
}
//call this function again - this will run in a continuous loop
show_list_item();
});
}
Upvotes: 3