Giter Site home page Giter Site logo

ngx-swiper-wrapper's Introduction

Angular Swiper Wrapper

npm version

This is an Angular wrapper library for the Swiper. To use this library you should get familiar with the Swiper documentation as well since this documentation only explains details specific to this wrapper.

This documentation is for the latest 6.x.x version which requires Angular 5 or newer. For Angular 4 you need to use the latest 4.x.x version. Documentation for the 4.x.x can be found from here.

EOL notice

Version 10.0.0 will be last release of this library since this is now obsolete due to latest Swiper including direct support for Angular.

Quick links

Example application | StackBlitz example | Swiper documentation

Building the library

npm install
npm run build

Running the example

npm install
npm run start

Installing and usage

npm install ngx-swiper-wrapper --save
Load the module for your app (with global configuration):

Providing the global configuration is optional and when used you should only provide the configuration in your root module.

import { SwiperModule } from 'ngx-swiper-wrapper';
import { SWIPER_CONFIG } from 'ngx-swiper-wrapper';
import { SwiperConfigInterface } from 'ngx-swiper-wrapper';

const DEFAULT_SWIPER_CONFIG: SwiperConfigInterface = {
  direction: 'horizontal',
  slidesPerView: 'auto'
};

@NgModule({
  ...
  imports: [
    ...
    SwiperModule
  ],
  providers: [
    {
      provide: SWIPER_CONFIG,
      useValue: DEFAULT_SWIPER_CONFIG
    }
  ]
})
Use it in your HTML template (with custom configuration):

This library provides two ways to create a Swiper element, component for simple use cases and directive for more custom use cases.

COMPONENT USAGE

Simply replace the element that would ordinarily be passed to Swiper with the swiper component.

NOTE: Component provides default elements for the scrollbar, navigation and pagination which you can enable by setting the appropriate configuration to 'true' or by using the default selector. If you want to use custom elements then you might want to use the directive instead.

<swiper [config]="config" [(index)]="index">
  <div>
    Swiper slide content
  </div>
</swiper>
[config]                // Custom config to override the global defaults.

[index]                 // Can be used to set the active slide index.
[disabled]              // Disables changing of slides (locks the Swiper).

[useSwiperClass]        // Use 'swiper' class (use provided default styles).

(indexChange)           // Event handler for the Swiper index change event.

(<swiperEvent>)         // All Swiper events / callbacks work as bindings.
                        // Conflicting events are prefixed with 'swiper':
                        // click, tap, doubleTap, touch*, transition*
                        // Example: touchStart -> swiperTouchStart

DIRECTIVE USAGE

When using only the directive you need to provide your own theming or import the default theme:

@import '~swiper/swiper-bundle.min.css';

Swiper directive can be used in correctly structured div element with optional custom configuration:

<div  class="swiper-container" [swiper]="config" [(index)]="index">
  <div class="swiper-wrapper">
    <div class="swiper-slide">
      Swiper slide content
    </div>
  </div>

  <div class="swiper-scrollbar"></div>
  <div class="swiper-pagination"></div>

  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>
</div>
[swiper]                // Can be used to provide optional custom config.

[index]                 // Can be used to set the active slide index.
[disabled]              // Disables changing of slides (locks the Swiper).
[performance]           // Emit all Swiper events outside the Angular zone.

(indexChange)           // Event handler for the Swiper index change event.

(<swiperEvent>)         // All Swiper events / callbacks work as bindings.
                        // Conflicting events are prefixed with 'swiper':
                        // click, tap, doubleTap, touch*, transition*
                        // Example: touchStart -> swiperTouchStart
Available configuration options (custom / global configuration):

This library supports all Swiper configuration options and few extra options for easier usage.

observer                // Set to to true to enable automatic update calls.
direction               // Direction of the Swiper (Default: 'horizontal').
threshold               // Distance needed for the swipe action (Default: 0).
spaceBetween            // Space in pixels between the Swiper items (Default: 0).
slidesPerView           // Number of the items per view or 'auto' (Default: 1).
centeredSlides          // Align active item on center not left (Default: false).

For more detailed documentation with all the supported events / options see the Swiper documentation.

Available control / helper functions (provided by the directive):
swiper()                          // Returns reference to the Swiper instance.

init()                            // Starts Swiper (when init set to false).
update()                          // Updates Swiper elements / classes / etc.

getIndex(real?)                   // Returns the active or real slide index.
setIndex(index, speed?, silent?)  // Runs transition to slide with given index.

nextSlide(speed?, silent?)        // Runs transition to the next slide index.
prevSlide(speed?, silent?)        // Runs transition to the previous slide index.

stopAutoplay(reset?)              // Stops and optionally resets the autoplay.
startAutoplay(reset?)             // Starts and optionally resets the autoplay.

Above functions can be accessed through the directive reference (available as directiveRef in the component).

ngx-swiper-wrapper's People

Contributors

amr-alamir avatar antti-pyykkonen avatar bombergio avatar criban avatar fredrikborgstrom avatar glebmachine avatar nosovk avatar rk-7 avatar rosslavery avatar sconix avatar valorkin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.