How to modify Elastislide so it loops infinitely

后端 未结 7 1128
庸人自扰
庸人自扰 2021-01-21 08:42

I\'ve been searching for an image carousel that will display several images at once, is responsive and loops infinitely.

Elastislide seems to be the most suitable ( http

7条回答
  •  借酒劲吻你
    2021-01-21 09:26

    Elastislide code has evolved and the above solution does not work. So I have developed my own solution.

    This code makes elastislide autoplay and when arrived at last slide it returns to the first slide to be more ergonomic than the infinite loop caroussel.

    This code should be added in the _initEvents function after var self = this;

    var translation = 0;
    // width/height of an item ( 
  • ) var itemSpace = this.options.orientation === 'horizontal' ? this.$items.outerWidth( true ) : this.$items.outerHeight( true ); // total width/height of the
      var totalSpace = this.itemsCount * itemSpace; // visible width/height var visibleSpace = this.options.orientation === 'horizontal' ? this.$carousel.width() : this.$carousel.height(); //slide auto window.setInterval(function(){ //test if we should go to next slide or return to first slide if(totalSpace > translation + visibleSpace) { //go to next slide self._slide('next'); //update translation translation += visibleSpace; } else { //return to first slide (infinite loop is too bad for ergonomics) self._slideTo(0); //set translation to 0 translation = 0; } }, 7000);
提交回复
热议问题