Notice: The Monaca & Onsen UI Community Forum is shutting down.

For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.

Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.

Excuse me,How can Carousel it be Loop Playback



  • Excuse me,How can Carousel it be Loop Playback React



  • @skyliwq,

    Based on the following: https://onsen.io/v2/api/js/ons-carousel.html

    Here you go! I adjusted the code based on the available methods and propeties of the ons-carousel.

    var prev = function() {
      var carousel = document.getElementById('carousel');
      
      if (carousel.getActiveIndex() === 0)
         carousel.last();
      else
         carousel.prev();
    };
    
    var next = function() {
      var carousel = document.getElementById('carousel');
      // alert(carousel.getActiveIndex());
      if (carousel.getActiveIndex() === carousel.itemCount-1)
         carousel.first();
      else
         carousel.next();
    };
    
    ons.ready(function() {
      var carousel = document.addEventListener('postchange', function(event) {
        console.log('Changed to ' + event.activeIndex)
      });
    });
    


  • ![0_1518399090816_bug222.gif](Uploading 100%)

    React carousel Bug?