tags:

views:

25

answers:

2

I want to basically slide all my li's up and the top one, will append to the bottom and it will be a rotation of upcoming events.

This is what i have so far. It slides the first one up and appends it to the end of ul, but then it just keeps appending that same li to the ul every 1000 ms.

Why doesn't it keep sliding the first one up? I'm assuming i have to use the live function somehow??

$(document).ready(function() {

    function scroll() {
        $('#events ol li:first').slideUp();

        $('#events ol li:last').appendTo($('#events ol'));
    }


    setInterval(scroll, 1000);
});
+2  A: 

One mistake I see, is that your appending the last li, appending the last item will not do any difference because it's already the last item...

demo

$(document).ready(function() {

    function scroll() {
      $('#events ol li:first-child').slideUp(function(){
        $(this).appendTo($('#events ol')).show();
      });       
   }

   setInterval(scroll, 1000);​
});
Reigel
+3  A: 

You need to change it up a bit to append itself after sliding up, like this:

$(function() {
  function scroll() {
    $('#events ol li:first').slideUp(function() {
      $(this).show().parent().append(this);
    });
  }
  setInterval(scroll, 1000);
});

You can see it in a demo here. What we're doing is after the .slideUp() completes, the callback runs, which takes the element, shows it (since it was hidden at the end of the .slideUp()) and does a .append() of itself to its parent...moving it to the end.

Nick Craver
Is there something like `slideUp()` that _reveals_ an element rather than hides it? And if so, could you clone the `LI` and have it slide up and disappear at the top while sliding in and appearing at the bottom simultaneously? I think that would make a better "scrolling" effect, but I don't know how easily it could be achieve using jQuery.
Lèse majesté
@Lèse - Is this what you're after? http://jsfiddle.net/nick_craver/g6uMF/2/
Nick Craver
That's exactly what I was looking for; I hadn't realized that `slideDown()` worked like that. But it all makes sense now that I've looked at the documentation. Thanks.
Lèse majesté