1.5.2 • Published 3 years ago

ngx-slickjs v1.5.2

Weekly downloads
79
License
MIT
Repository
github
Last release
3 years ago

ngx-slickjs

Minzipped Size Build Status Codecov GitHub npm Follow Twitter

ngx-slickjs is slick-carousel package for Angular 6+. ngx-slickjs can lazy load slick.js packages. ngx-slickjs very small and very stable.

Stackblitz Example

Installation

yarn add ngx-slickjs

or

npm install ngx-slickjs

Usage

Import module to your main module

import { NgxSlickJsModule } from "ngx-slickjs";

@NgModule({
  imports: [
    // ...
    NgxSlickJsModule.forRoot()
  ]
})
export class AppModule {}
<div slickContainer id="your-slide-container">
  <img slickItem id="your-slide" src="https://placeholder.pics/svg/400" />
  <img slickItem id="your-slide-2" src="https://placeholder.pics/svg/400" />
</div>

You can use slick methods. SlickContainerDirective exported with slick key.

<div slickContainer #slickController="slick">
  <img
    slickItem
    *ngFor="let item of [0,1,2,3,4,5];"
    src="https://placeholder.pics/svg/400"
  />
</div>

<button (click)="slickController.next()">Next</button>
<button (click)="slickController.prev()">Previous</button>
<button (click)="slickController.goTo(4)">Go to 4</button>
<button (click)="slickController.play()">Play</button>
<button (click)="slickController.pause()">Pause</button>
<button (click)="slickController.unslick()">Destroy</button>
<button (click)="slickController.initSlick()">Init</button>

Sub Module Import

import { NgxSlickJsModule } from "ngx-slickjs";

@NgModule({
  imports: [
    // ...
    NgxSlickJsModule
  ]
})
export class AnotherModule {}

Scripts and styles urls

forRoot Options:

PropertyDefault
jqueryhttps://code.jquery.com/jquery-3.4.0.min.js
slickJshttps://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js
slickCsshttps://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css
slickThemeCsshttps://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick-theme.css

Note: The above urls are download lazy. The urls don't increase initial opening time.

Example:

import { NgxSlickJsModule } from "ngx-slickjs";

@NgModule({
  imports: [
    // ...
    NgxSlickJsModule.forRoot({
      links: {
        jquery: "https://code.jquery.com/jquery-3.4.0.min.js",
        slickJs:
          "https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js",
        slickCss:
          "https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css",
        slickThemeCss: null // if you are set null, this css won't load
      }
    })
  ]
})
export class AppModule {}

Input and outputs:

Inputs:

NameDefault
slickConfigundefined

Outputs:

EventParamsDescription
slickAfterChangeevent, slick, currentSlideAfter slide change callback
slickBeforeChangeevent, slick, currentSlide, nextSlideBefore slide change callback
slickBreakpointevent, slick, breakpointFires after a breakpoint is hit
slickDestroyevent, slickWhen slider is destroyed, or unslicked.
slickInitevent, slickWhen Slick initializes for the first time callback. Note that this event should be defined before initializing the slider.

You can import Slick config type:

import { Slick } from "ngx-slickjs";

slickConfig: Slick.Config = {
  infinite: true,
  slidesToShow: 4,
  slidesToScroll: 2,
  dots: true,
  autoplay: true,
  autoplaySpeed: 2000
};

Config

OptionTypeDefaultDescription
accessibilitybooleantrueEnables tabbing and arrow key navigation. Unless autoplay: true, sets browser focus to current slide (or first of current slide set, if multiple slidesToShow) after slide change. For full a11y compliance enable focusOnChange in addition to this.
adaptiveHeightbooleanfalseAdapts slider height to the current slide
appendArrowsstring\$(element)Change where the navigation arrows are attached (Selector, htmlString, Array, Element, jQuery object)
appendDotsstring\$(element)Change where the navigation dots are attached (Selector, htmlString, Array, Element, jQuery object)
arrowsbooleantrueEnable Next/Prev arrows
asNavForstring\$(element)Enables syncing of multiple sliders
autoplaybooleanfalseEnables auto play of slides
autoplaySpeedint3000Auto play change interval
centerModebooleanfalseEnables centered view with partial prev/next slides. Use with odd numbered slidesToShow counts.
centerPaddingstring'50px'Side padding when in center mode. (px or %)
cssEasestring'ease'CSS3 easing
customPagingfunctionn/aCustom paging templates. See source for use example.
dotsbooleanfalseCurrent slide indicator dots
dotsClassstring'slick-dots'Class for slide indicator dots container
draggablebooleantrueEnables desktop dragging
easingstring'linear'animate() fallback easing
edgeFrictioninteger0.15Resistance when swiping edges of non-infinite carousels
fadebooleanfalseEnables fade
focusOnSelectbooleanfalseEnable focus on selected element (click)
focusOnChangebooleanfalsePuts focus on slide after change
infinitebooleantrueInfinite looping
initialSlideinteger0Slide to start on
lazyLoadstring'ondemand'Accepts 'ondemand' or 'progressive' for lazy load technique. 'ondemand' will load the image as soon as you slide to it, 'progressive' loads one image after the other when the page loads.
mobileFirstbooleanfalseResponsive settings use mobile first calculation
nextArrowstring (html | jQuery selector) | object (DOM node | jQuery object)<button type="button" class="slick-next">Next</button>Allows you to select a node or customize the HTML for the "Next" arrow.
pauseOnDotsHoverbooleanfalsePauses autoplay when a dot is hovered
pauseOnFocusbooleantruePauses autoplay when slider is focussed
pauseOnHoverbooleantruePauses autoplay on hover
prevArrowstring (html | jQuery selector) | object (DOM node | jQuery object)<button type="button" class="slick-prev">Previous</button>Allows you to select a node or customize the HTML for the "Previous" arrow.
respondTostring'window'Width that responsive object responds to. Can be 'window', 'slider' or 'min' (the smaller of the two).
responsivearraynullArray of objects containing breakpoints and settings objects (see example). Enables settings at given breakpoint. Set settings to "unslick" instead of an object to disable slick at a given breakpoint.
rowsint1Setting this to more than 1 initializes grid mode. Use slidesPerRow to set how many slides should be in each row.
rtlbooleanfalseChange the slider's direction to become right-to-left
slidestring''Slide element query
slidesPerRowint1With grid mode initialized via the rows option, this sets how many slides are in each grid row.
slidesToScrollint1# of slides to scroll at a time
slidesToShowint1# of slides to show at a time
speedint300Transition speed
swipebooleantrueEnables touch swipe
swipeToSlidebooleanfalseSwipe to slide irrespective of slidesToScroll
touchMovebooleantrueEnables slide moving with touch
mouseWheelMovebooleantrueEnables slide moving with mouse wheel
touchThresholdint5To advance slides, the user must swipe a length of (1/touchThreshold) * the width of the slider.
useCSSbooleantrueEnable/Disable CSS Transitions
useTransformbooleantrueEnable/Disable CSS Transforms
variableWidthbooleanfalseDisables automatic slide width calculation
verticalbooleanfalseVertical slide direction
verticalSwipingbooleanfalseChanges swipe direction to vertical
waitForAnimatebooleantrueIgnores requests to advance the slide while animating
zIndexnumber1000Set the zIndex values for slides, useful for IE9 and lower
Responsive Option Example

The responsive option, and value, is quite unique and powerful. You can use it like so:

$(".slider").slick({
  // normal options...
  infinite: false,

  // the magic
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        infinite: true
      }
    },
    {
      breakpoint: 600,
      settings: {
        slidesToShow: 2,
        dots: true
      }
    },
    {
      breakpoint: 300,
      settings: "unslick" // destroys slick
    }
  ]
});

Bonus

LazyLoadService Usage

import {LazyLoadService} from 'ngx-slickjs';

constructor(private lazyLoadService: LazyLoadService) {}

  ngAfterViewInit(){
    this.lazyLoadService
      .load(yourScriptUrl, 'script')
      .subscribe(() => {
        // loaded your script
      });

    this.lazyLoadService
      .load(yourCssUrl, 'style')
      .subscribe(() => {
        // loaded your css
      });
  }
1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago