JCarousel circular “no stop”

2019-07-24 14:12发布

问题:

It is possible to configure JCarousel for a circular "no stop" ? I wish configure my carousel for a continuous constant circular moving. without slowing down.

Thanks

回答1:

To get it to constantly rotate you should be able to set auto:.1 and animation:5000 (or whatever speed you want. Below is an example that took me a long time to get going correctly. It is getting data through jQuery AJAX.

    var lis;  //Global variable holding the data.
    var myCarousel01;  //Global variable holding the carousel.

    $(document).ready(function () {
        updateData();

        $("#tableapp").ajaxStop(function () {  
                InitiateCarousels();
            }

            rebindCarousels();
        });

    });

    function updateData() {
        $.get('AjaxPages/ApplicationMonitor.aspx', function (data) {
            lis = $(data).find("li");
        });
    }

function InitiateCarousels() {
 jQuery('#mycarousel1').jcarousel({
   wrap: 'circular',
   auto:.1,   //Amount of time you want slide to stop in seconds
   animation:5000,   //Desired speed in milliseconds
   easing:"linear", //Prevents the slides from "slowing down"
   initCallback: myCarousel01_initCallback,
   itemFirstInCallback: myCarousel01_itemFirstInCallback
 });
});

function myCarousel01_initCallback(carousel, state) {
     if (state == "init") {
         myCarousel01 = carousel;  //Bind carousel to global variable so you can retrieve it later.
     }
}


    function rebindCarousels() {  //This function gets called after data is binded to the lis variable.  See: "ajaxStop" function above.
        //Rebind Carousel01
        myCarousel01.list.empty();
        $.each(lis, function (i, l) {
            myCarousel01.add(i + 1, l);
        });
        myCarousel01.size(lis.length);
    }

Hope this helps someone. It took a while to get this working and I did a rough copy/paste here so it may take a little tweaking. If this helps, please mark it as answered.