简体   繁体   中英

mcustom Scrollbar autoscroll Issue

I am trying to create a div with content scrolling horizontally after a specific period of time - Like a slide show. I am using mcustomscollbar plugin. I am using a for loop to increment the id's and using the scrollTo function to slide the content but the scroll jumps to the last one.

Here its the js

for (var num = 1; num < 24; num++) {
    var idj = '#' + 'id' + num;
    var dlp = scrollToI(idj);
}

    function scrollToI(person) {
    setTimeout(function () {
        console.log(person);
        $('#content1').mCustomScrollbar("scrollTo", person);
    }, 2000);
}

Fiddle : http://jsfiddle.net/infern00/3psLU/

ScrollBar Plugin used : http://manos.malihu.gr/jquery-custom-content-scroller/

You mean something like this:

 $(document).ready(function () {
    $("#content1").mCustomScrollbar({
       axis: "x",
       theme: "dark-thick",
       advanced: {
          autoExpandHorizontalScroll: true
       }
    });
    var i = 1;

    var interval = setInterval(function () {
       var idj = '#' + 'id' + i;
       console.log(idj);
       scrollToI(idj);
       if (i > 23) clearInterval(interval);

       i++;
    }, 2000);


    function scrollToI(person) {
        $('#content1').mCustomScrollbar("scrollTo", person);
    }
});

Check the FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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