ThierryDD
4/16/2018 - 4:16 PM

Swipe Gesture - Photo Swiping in Album Component

// ...
@Component({
  // ...
})
export class AlbumComponent {

  // ...

  @HostListener('swipeLeft') slideLeft() { this.slide(1); }
  @HostListener('swipeRight') slideRight() { this.slide(-1); }

  // ...

  slide(offset) {
    const nbPhotos = this.album.photos.length;
    this.current = (((this.current + offset) % nbPhotos) + nbPhotos) % nbPhotos;
  }

}