Run jCarouselLite again, after an AJAX request

限于喜欢 提交于 2019-12-12 03:21:50

问题


I am using jCarouselLite to show a post scroller, which loads posts from a specific category. But, I want to be able to switch the category via AJAX.

So, I load up everything in a div, and then run:

jQuery(function($) {
$("#serviceNews").jCarouselLite({
    vertical: true,
    hoverPause:true,
    visible: 2,
    auto:2000,
    speed:1000
});

});

And it works... up until ajax refreshes the innerHTML of the #serviceNews. Then jCarouselLite stops working. I've tried using livequery:

jQuery(function($) {
$("#serviceNews").livequery(function(){
    $(this).jCarouselLite({
        vertical: true,
        hoverPause:true,
        visible: 2,
        auto:2000,
        speed:1000
    });
});

});

But the same thing happens. I am not very familiar with jQuery, so I'm probably missing out something obvious.

You can find the demo here (the middle column, below the banner, with the switchCategory buttons below the scroller).


回答1:


hope you are using the latest code https://github.com/kswedberg/jquery-carousel-lite

the documentation mentions here that you could end the carousel with

$('div.carousel').trigger('endCarousel')

So every time you need to update the carousel just endCarousel and then again bind the jCarouselLite to the div




回答2:


The solution from maniac_user is working for me.

Try to set a :

$("div.carousel").trigger("endCarousel");

Before your jCarousel code :

$(".auto .jCarouselLite").jCarouselLite({
  speed: 14700,
  btnNext: ".next",
  vertical: true,
  hoverPause:true,
  visible: 1
});


来源:https://stackoverflow.com/questions/9424499/run-jcarousellite-again-after-an-ajax-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!