Giter VIP home page Giter VIP logo

angular-swiper's Introduction

angular-swiper

Directive that wraps nolimits4web/swiper library for AngularJS. License: Apache

1 Installation

bower install angular-swiper

2 Development

npm install -g gulp
npm install
bower install

3 Usage

3.1 Requirements

Add <script>s to your html files for angular and angular-swiper:

    <link rel="stylesheet" href="bower_components/swiper/dist/css/swiper.min.css">
    
    <script src="../bower_components/swiper/dist/js/swiper.js"></script>
    <script src="../bower_components/angular/angular.js"></script>
    <script src="../dist/angular-swiper.js"></script>

And add ksSwiper as a dependency for your app:

angular.module('myApp', ['ksSwiper', ...]);

3.2 Sample Markup

Example:

<ks-swiper-container initial-slide="3" loop="false" show-nav-buttons="false" slides-per-view="4" space-between="5" pagination-clickable="false">
    <ks-swiper-slide class="swiper-slide" ng-repeat="s in [1,2,3,4,5,6,7,8,9,10,11,12,13,14]">
        <img ng-src="http://api.randomuser.me/portraits/thumb/men/{{s}}.jpg">
    </ks-swiper-slide>
</ks-swiper-container>

3.3 Directive default values

If no attributes are given, an object with the following values will be used to initiate the swiper. It is possible to use the directive without specifying attributes.

// directive defaults
var params = {
    slidesPerView: $scope.slidesPerView || 1,
    slidesPerColumn: $scope.slidesPerColumn || 1,
    spaceBetween: $scope.spaceBetween || 0,
    direction: $scope.direction || 'horizontal',
    loop: $scope.loop || false,
    initialSlide: $scope.initialSlide || 0,
    showNavButtons: false
};

3.4 Possible Attributes

The following attributes can be used with this directive. Please see the Swiper API Documentation for more information about the type and description of parameters.

<ks-swiper-container
    slides-per-view="3"
    slides-per-column="1"
    space-between="0"
    pagination-is-active="true"
    pagination-clickable="false"
    show-nav-buttons="false"
    loop="false"
    autoplay="5000"
    initial-slide="0"
    direction="horizontal">
    ...
</ks-swiper-container>

3.5 Override any parameter

This allows you to pass a javascript object that will override any swiper parameter from the Swiper API Documentation that is used initialize swiper.

Example:

<ks-swiper-container override-parameters="{'effect':'cube'}">
    <ks-swiper-slide class="swiper-slide" ng-repeat="s in [1,2,3,4,5,6,7,8,9,10,11,12,13,14]">
      <img ng-src="http://api.randomuser.me/portraits/thumb/men/{{s}}.jpg">
    </ks-swiper-slide>
</ks-swiper-container>

3.6 Two-Way Binding of Swiper

In some situations it might be useful to access the actual swiper instance. Passing the parent scope will linked it to the model in the directive's isolated scope which is used for the swiper instance.

It can also be used to slideTo(index, speed, runCallbacks), slidePrev(runCallbacks, speed), slideNext(runCallbacks, speed) or for callback functions.

Example Template:

<div ng-controller="TestCtrl">
<ks-swiper-container swiper="swiper">
    <ks-swiper-slide class="swiper-slide" ng-repeat="s in [1,2,3,4,5,6,7,8,9,10,11,12,13,14]">
      <img ng-src="http://api.randomuser.me/portraits/thumb/men/{{s}}.jpg">
    </ks-swiper-slide>
</ks-swiper-container>
</div>

Example Controller

angular.module('swiperApp')
  .controller('TestCtrl', function($scope){

    $scope.swiper = {};

    $scope.next = function(){
      $scope.swiper.slideNext();
    };

  });

3.7 Accessing swiper object after it's created

In some situations, like when you wanna listen to swiper events, is useful to know when the swiper object is created (that occurs after all slides are created).

For that purpose is available the on-ready attribute. You can specify a function to be called when the swiper object is created. In the function you can manipulate the swiperobject, and for example, bind an event. The function must has a paramteter called swiper, refering to swiper object.

Example template

<div ng-controller="TestCtrl">
<ks-swiper-container swiper="swiper" on-ready="onReadySwiper(swiper)">
    <ks-swiper-slide class="swiper-slide" ng-repeat="s in [1,2,3,4,5,6,7,8,9,10,11,12,13,14]">
      <img ng-src="http://api.randomuser.me/portraits/thumb/men/{{s}}.jpg">
    </ks-swiper-slide>
</ks-swiper-container>
</div>

Example Controller

angular.module('swiperApp')
  .controller('TestCtrl', function($scope){

    $scope.swiper = {};

    $scope.onReadySwiper = function (swiper) {
      
      swiper.on('slideChangeStart', function () {
      
        console.log('slideChangeStart');
      });
    };

  });

angular-swiper's People

Contributors

ksachdeva avatar aaronroberson avatar estoeckli avatar quedicesebas avatar andyhan1001 avatar ivangabriele avatar jwoodjr avatar mohammad6006 avatar lixiaoxin avatar

Watchers

Nitin Nayar 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.