Reputation: 65
<style>
.myNewsSlider
{
width:200px;
height:44px;
overflow:hidden;
position:relative;
}
.myNewsList
{
margin:0px;
padding:0px;
position: absolute;
}
</style>
<div class="myNewsSlider">
<ul class="myNewsList">
<li>first element</li>
<li>second element</li>
<li>third element</li>
</ul>
</div>
I want the list to move from bottom to top and show each element for 5 seconds.
The first element will show for 5 seconds, then disappear, and the second element will show for 5 seconds, etc.
How do I use Jquery to complete this task?
Upvotes: 3
Views: 3380
Reputation: 4215
var p;
for(i=0;i<=3;i++){
p=i*20;
$('.myNewsList').animate({"margin-top":"-"+p+"px"},1000).delay(5000);
}
.myNewsSlider
{
width:200px;
height:24px;
overflow:hidden;
position:relative;
}
Upvotes: 1
Reputation: 34117
Working demo much simpler : http://jsfiddle.net/aLprr/
APIs used:
.promise
- http://api.jquery.com/promise/.delay
- http://api.jquery.com/delay/.fadeOut
- http://api.jquery.com/?ns0=1&s=.fadeOut&go=Hope it fits the cause :)
P.S. - play around with the 5000 calculation.
Code
$("document").ready(function() {
$('ul li').each(function(index) {
$(this).delay(4000 * index).fadeOut(500).promise(function() {
$(this).remove();
});
});
});
Upvotes: 2
Reputation: 32827
An easy way to do this would be to
1]set myNewsList's li
's margin-top
property to 100%
;
2]Tell jquery to animate
myNewsList's li
by making its margin-top
to 0%
3]for the 5 seconds
delay,you can use the setInterval()
method where you can hide the first li of myNewsList after every 5 seconds and then animate the second li
by setting it's top-margin
to 0%.If all li's are hidden,again start from the first li
..
Upvotes: 0