admin管理员组

文章数量:1336437

I want to add a new custom effect to the Swiper slider JavaScript library.

The default Swiper effects are slide, fade, cube, coverflow or flip but I want to add my custom effect with and all events. How can I do that?

I want to add a new custom effect to the Swiper slider JavaScript library.

The default Swiper effects are slide, fade, cube, coverflow or flip but I want to add my custom effect with and all events. How can I do that?

Share edited Jan 10, 2019 at 19:18 Giao1968 26k11 gold badges76 silver badges105 bronze badges asked May 17, 2017 at 9:09 miladfmmiladfm 1,52613 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6
  1. Go to the s.effects object (Effects part) in swiper.js and add your own effect property like this:

    myEffect: {
       setTranslate: function() {
           // your actual animation code goes here
       },
       setTransition: function( duration ) {
           // duration is between 0 and max speed (300 is default)
           // but you can change it in the config object below
           // is called when your swiping starts and ends
       }
    }
    
  2. To use your new effect do this:

    var mySwiper = new Swiper( '.swiper-container', {
           // other options …
           // and add this
           effect: “myEffect”
       }
    );
    

For more information have a look here: https://github./nolimits4web/Swiper/issues/1497

本文标签: swiperjsHow to add custom effects to the Swiper slider JavaScript libraryStack Overflow