1.6.0 • Published 5 years ago

intouch-screensaver v1.6.0

Weekly downloads
15
License
MIT
Repository
github
Last release
5 years ago
 _  _      ___ _            _     ___ _ _    _        _
| \| |__ _/ __(_)_ __  _ __| |___/ __| (_)__| |___ __| |_  _____ __ __
| .` / _` \__ \ | '  \| '_ \ / -_)__ \ | / _` / -_|_-< ' \/ _ \ V  V /
|_|\_\__, |___/_|_|_|_| .__/_\___|___/_|_\__,_\___/__/_||_\___/\_/\_/
     |___/            |_|

A simple slideshow for Angular 4+.

Click here the check out the demo. Click here the see the slideshow in production on a StoragePug client site, which is what I originally made this slideshow package for.

Features

  • NgSimpleSlideshow has no dependencies besides angular. All animations are 100% CSS, so @angular/animations is not needed.
  • Compiled and packaged in the Angular Package Format v4.0 with ng-packagr.
  • Compiled to es5, so this package is compatible with Angular Universal.
  • AOT ready
  • Responsive and captures swipes from phones and tablets
  • Lazy load option to help with initial pageload speed

Installation

Easy, just npm install:

npm i -S intouch-screensaver

Next, import the module:

import {SlideshowModule} from 'intouch-screensaver';

@NgModule({
  imports: [
    SlideshowModule,
    ...
  ],
  declarations: [
    ...
  ],
  exports: [
    ...
  ]
})
...

Usage

The simplest use case is the following:

<slideshow [imageUrls]="imageUrlArray"></slideshow>

A more complex example of how I use this in one of my own projects (full list of options in next section):

<slideshow [height]="height"
           [minHeight]="'525px'"
           [autoPlay]="true"
           [showArrows]="false"
           [imageUrls]="imageSources"
           [lazyLoad]="imageSources?.length > 1"
           [autoPlayWaitForLazyLoad]="true">
</slideshow>

More Info on imageUrls

The imageUrls input can be an array of strings, however in order to enable slides to have links, captions, or custom click functions, you must use an object of type IImage instead of a string. For example usage, see here.

Options

Inputs

OptionRequiredDefaultTypeDescription
imageUrlsyes[]string[] or IImage[]array of image urls or IImage
heightno'100%'stringCSS height of slideshow
minHeightnostringCSS min-height of slideshow
arrowSizeno'30px'stringlength of arrow lines
showArrowsnotruebooleanshow or hide the arrows
disableSwipingnofalsebooleanturn swipe detection on or off
autoPlaynofalsebooleanturn autoPlay on or off
autoPlayIntervalno3333numbertime in ms between autoPlay slides
stopAutoPlayOnSlidenotruebooleanstop autoPlay if slideshow is interacted with
autoPlayWaitForLazyLoadnofalsebooleanautoplay to waits for images to lazy load before changing slides
backgroundSizeno'cover'stringoverwrite background-size property
backgroundPositionno'center center'stringoverwrite background-position property
backgroundRepeatno'no-repeat'stringoverwrite background-repeat property
showDotsnofalsebooleanshow clickable dots at the bottom
dotColorno'#FFF'stringcolor of clickable dots at the bottom
showCaptionsnotruebooleanshow or hide captions
captionColorno'#FFF'stringcolor of caption text
captionBackgroundno'rgba(0, 0, 0, .35)'stringcolor of caption background
lazyLoadnofalsebooleanturn on to lazy load images instead of preload
hideOnNoSlidesnofalsebooleanset the slideshow container display to none if imageUrls is empty, null, or undefined

Output Events

EventDescription
onSlideLeftwhen the left arrow is clicked
onSlideRightwhen the right arrow is clicked
onSwipeLeftwhen a swipe left occurs
onSwipeRightwhen a swipe right occurs

Note: all events emit the index number of the new slide

API

Take control of the slideshow if you want! Simply create a reference to your slideshow like so:

<slideshow #slideshow [imageUrls]="imageUrlArray"></slideshow>

and in your component.ts reference it as a ViewChild:

@ViewChild('slideshow') slideshow: any;

Now you can access the public members such as the goToSlide and onSlide:

this.slideshow.goToSlide(3); // go to slide index 3 (i.e. imageUrls[3])
this.slideshow.onSlide(1); // next slide
this.slideshow.onSlide(-1); // previous slide