ngu-carousel icon indicating copy to clipboard operation
ngu-carousel copied to clipboard

Infinite loop

Open dottodot opened this issue 6 years ago • 8 comments

Would it be possible to make the loop option infinite so when it get to the last slide it continues to the first with scrolling back to opposite direction.

dottodot avatar Jan 18 '18 09:01 dottodot

@dottodot currently not possible but in near future will try to update.

sheikalthaf avatar Jan 21 '18 07:01 sheikalthaf

This is how i made my infinite slider, but the problem is the animation when going from last to first slide or first to last slide.

But good work, thanks for sharing. This is the only slider/swiper/carousel I could find that works with data binding in angular.

import { Component } from '@angular/core';
import { CustomerService } from "../../app/services/data/wrapper/customer-wrapper.service";
import 'hammerjs';

@IonicPage()
@Component({
  selector: 'page-customer-slide',
  templateUrl: 'customer-slide.html',
})
export class CustomerPageSlide {

  // swiper data
  itemIndex: number = 0;
  customers: any[] = [
    { name: 'laaa', no: 1, city: 'yaaa' }, { name: 'l', no: 2, city: 'yooo' }, { name: 'laa', no: 3, city: 'yiii' },
    { name: 'daaa', no: 4, city: 'daaa' }, { name: 'do', no: 5, city: 'dooo' }, { name: 'di', no: 6, city: 'diii' }
  ];

  slides: any[] = [null, null, null];
  slideCurrent: number = 0;
  slidePrevious: number = 0;

  // swiper
  carouselTile = {
    grid: { xs: 1, sm: 1, md: 1, lg: 1, all: 0 },
    slide: 1,
    speed: 400,
    animation: 'lazy',
    point: {
      visible: false
    },
    load: 2,
    touch: true,
    easing: 'ease',
    loop: true
  }

  constructor() {
  }

  ngOnInit() {
    this.slides[0] = this.customers[0];
    this.slides[1] = this.customers[1];
    this.slides[2] = this.customers[2];
  }

  public carouselTileLoad(event) {

    // update slider index
    this.slideCurrent = event;
    let previous_index = this.slideCurrent === 0 ? 2 : this.slideCurrent - 1;
    let next_index = this.slideCurrent === 2 ? 0 : this.slideCurrent + 1;

    // update item index
    if (previous_index == this.slidePrevious) {
      console.log('slide up');
      this.itemIndex = this.findNextIndex(this.itemIndex);
    }
    if (next_index == this.slidePrevious) {
      console.log('slide down');
      this.itemIndex = this.findPreviousIndex(this.itemIndex);
    }

    // update slider with items
    this.slides[previous_index] = this.customers[this.findPreviousIndex(this.itemIndex)];
    this.slides[this.slideCurrent] = this.customers[this.itemIndex];
    this.slides[next_index] = this.customers[this.findNextIndex(this.itemIndex)];

    // keep slidePrevious to determine if we slided up or down
    this.slidePrevious = this.slideCurrent;
  }

  private findNextIndex(index) {
    return this.itemIndex + 1 === this.customers.length ? 0 : this.itemIndex + 1;
  }

  private findPreviousIndex(index) {
    return this.itemIndex - 1 === -1 ? this.customers.length - 1 : this.itemIndex - 1;
  }
}

pablomaurer avatar Jan 23 '18 09:01 pablomaurer

can you give code how to make it in infinite loop ???????????? please

hemanthsp avatar Mar 01 '18 05:03 hemanthsp

@hemanthsp I gave code write above your comment. But you can't use infinite loop currently due to animation-problems using this component.

pablomaurer avatar Mar 01 '18 08:03 pablomaurer

ha, finally i moved owl lib because of infinite loop

hemanthsp avatar Mar 01 '18 10:03 hemanthsp

Waiting for this feature. Would be very helpful.

romanzadorov avatar Mar 02 '19 17:03 romanzadorov

any updates about it?

hauzlife avatar Sep 26 '22 16:09 hauzlife

Would appreciate this feature any time soon

girlwhodrawsandstuff avatar Nov 22 '22 04:11 girlwhodrawsandstuff