1

我在我的一个项目中使用 jcarousellite。这是我到目前为止的代码。

$(".carousel").jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
    speed: 700,
    visible: 8,
    afterEnd: function(a){
        // set the now first element to the active video
        $(a[0]).addClass("active");
    },
});

唯一的问题是我的列表项直到

$(document).ready(function(){
  // generate list items
});

我想在加载列表项后生成我的轮播。我可以为此使用 jQuery 的 .live() 吗?有任何想法吗?

4

1 回答 1

0

在生成项目之前不要运行轮播插件。

$(document).ready(function(){

  // generate list items

  // then run the jCarouselLite
  $(".carousel").jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
    speed: 700,
    visible: 8,
    afterEnd: function(a){
        // set the now first element to the active video
        $(a[0]).addClass("active");
    },
  });

});

如果列表项是由于异步 AJAX 调用而生成的,则将轮播代码放在 AJAX 调用的回调中。

如果您要动态生成其他项目,则将对列表的引用存储在变量中,并仅针对这些项目调用轮播插件。

不,你不能用.live()这个。

于 2010-12-29T16:58:49.553 回答