2.0.2 • Published 4 years ago

ngx-code-gentleman-carousel v2.0.2

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

Note (09/2019):

v1.3.0-beta.2 will be in beta until I update the way ng-packagr works. It is stable enough for production (it's what I am using with Angular Universal and Service Worker).

Also, I am looking for maintainers who also using this package in a production app. I have this requirement because I need maintainers who have a vested interest in the quality of this package. Thanks.

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 ng-codeGentleman-carousel

Next, import the module:

import {SlideshowModule} from 'ng-codeGentleman-carousel';

@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
autoPlayWaitForLazyLoadnotruebooleanautoplay 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
fullscreennofalsebooleanactivate full screen for the slideshow on true, go back to normal view on false
enableZoomnofalsebooleanenable (2 point/pinch) touch zoom in/out on images
enablePannofalsebooleanenable (1 point) touch/click panning of images, NOTE: "true" will disable image on click actions
noLoopnofalsebooleanblock looping through slideshow like a circular list

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
onFullscreenExitwhen fullscreen exits
onIndexChangedwhen slide index changes
onImageLazyLoadwhen slide image lazy loads
onClickwhen slide (not arrows) is clicked

Note: all events emit the index number of the new slide, with the exception of onClick which returns the slide object in addition to the index.

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