简体   繁体   English

垂直JavaScript轮播

[英]Vertical JavaScript carousel

I am trying to write a simple vertical JavaScript carousel that'll rotate a couple of elements. 我正在尝试编写一个简单的垂直JavaScript轮播,该轮播会旋转几个元素。 It works quite well but I am having a hard time figuring out how to keep the amount of elements. 它工作得很好,但是我很难弄清楚如何保持元素数量。 As you can see in this JSFiddle, http://jsfiddle.net/xznfQ/2/ , the first one is "queued" away and reappears after a round. 如您在此JSFiddle中所见, http://jsfiddle.net/xznfQ/2/ ,第一个被“排队”了,在一轮之后再次出现。 Can anyone tell me what I am doing wrong? 谁能告诉我我在做什么错?

I guess something is wrong with these two lines: 我猜这两行有问题:

$(e).eq(1).slideUp('slow'); // Slide next element up over the previous $(e).eq(1).slideUp('slow'); // Slide next element up over the previous $(e).eq(0).appendTo(a).show('slow'); // Place the current element at the bottom $(e).eq(1).slideUp('slow'); // Slide next element up over the previous $(e).eq(0).appendTo(a).show('slow'); // Place the current element at the bottom $(e).eq(1).slideUp('slow'); // Slide next element up over the previous $(e).eq(0).appendTo(a).show('slow'); // Place the current element at the bottom $(e).eq(0).appendTo(a).show('slow'); // Place the current element at the bottom

Kind regards, 亲切的问候,

Mathias. Mathias。

You want to hide the first element, e(0) and only after that move it to the end! 您只想隐藏第一个元素e(0),然后将其移动到最后! You want: 你要:

    $(e).eq(0).slideUp('slow', function () {
        $(e).eq(0).appendTo(a).show('slow');
    });

Your code: 您的代码:

$(e).eq(1).slideUp('slow');

Slowly hides the element and returns immediately. 慢慢隐藏元素并立即返回。 Then: 然后:

$(e).eq(0).appendTo(a).show('slow');

Moves the first element to the end immediately and slowly shows it. 立即将第一个元素移到末尾并缓慢显示它。 This meant you had the second element disappearing and the first element appearing at the end. 这意味着您第二个元素消失了,而第一个元素出现在最后。 So the list had one hidden at all times. 因此,列表始终隐藏着一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM