简体   繁体   English

JQuery's.append() 执行 6 次而不是 1

[英]JQuery's .append() executes 6 times instead of 1

Basically, what I'm trying to do is create a marquee type thing by scrolling vertically through the banners and then moving each to the bottom after it is out of view.基本上,我想要做的是通过垂直滚动横幅然后将每个横幅移到底部,然后在它看不见后创建一个选框类型的东西。 I can't figure out why the banner is being appended six times.我无法弄清楚为什么横幅被附加了六次。 I realize that it's not quite complete so don't make a remark about that please.我意识到它并不完整,所以请不要对此发表评论。 If you have a better suggestion, let me know.如果你有更好的建议,请告诉我。 http://jsfiddle.net/vCuHc/2/ http://jsfiddle.net/vCuHc/2/

EDIT: How can I append the top element to the bottom and then remove the top element also?编辑:我怎样才能将顶部元素 append 移到底部,然后再移除顶部元素?

You have six elements with the same class.您有六个具有相同 class 的元素。 This script runs once for each of the those elements.该脚本对这些元素中的每一个运行一次。

Change the code that it runs once by appending to the parent div after the animations complete and not at the end of every animation.通过在动画完成后而不是在每个animation 的末尾附加到父 div 来更改它运行一次的代码。

It's being called against every element in the result of $('.tornado_banner') .针对$('.tornado_banner')结果中的每个元素调用它。

Instead of代替

function(){
...
        $("#banner_container").append(
            '<a class="tornado_banner" id="banner_alberta" href="#" style="top:' + elementNum * -130 + 'px">&nbsp;</a>'
        );

Try尝试

function(){
   $(this).detach().appendTo("#banner_container");
}

If I understand your edit correctly,如果我正确理解您的编辑,

var first = jQuery("#banner_container a:first");
jQuery("#banner_container").append(first);

That will remove the first element while appending it to the end of the list.这将删除第一个元素,同时将其附加到列表的末尾。

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

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