Swiper - 图1

Swiper Slider

Framework7 comes with powerful and most modern touch slider ever - Swiper Slider with super flexible configuration and lot, lot of features.

Swiper Slider HTML Layout

Swiper HTML layout is pretty simple:

  1. <!-- Slider container -->
  2. <div class="swiper-container">
  3. <!-- Slides wrapper -->
  4. <div class="swiper-wrapper">
  5. <!-- Slides -->
  6. <div class="swiper-slide">Slide 1</div>
  7. <div class="swiper-slide">Slide 2</div>
  8. <div class="swiper-slide">Slide 3</div>
  9. ... other slides ...
  10. </div>
  11. <!-- Pagination, if required -->
  12. <div class="swiper-pagination"></div>
  13. </div>

Where:

  • swiper-container - main slider container with slides and paginations. Required element

    • swiper-wrapper - additional wrapper for slides. Required element

      • swiper-slide - single slide element. Could contain any HTML inside
    • swiper-pagination - container with pagination bullets. Note, that pagination bullets will be created automatically. Optional element

Swiper App Methods

Now, when we have Swiper’ HTML, we need to initialize it. We need to use related App’s method:

app.swiper.create(swiperEl, parameters)- initialize slider with options

  • swiperEl - HTMLElement or string (with CSS Selector) of swiper container HTML element. Required.
  • parameters - object - object with Swiper parameters. Optional.
  • Method returns initialized Swiper instance

app.swiper.destroy(swiperEl)- destroy Swiper instance

  • swiperEl - HTMLElement or string (with CSS Selector) of swiper container HTML element. Required.

app.swiper.get(swiperEl)- get Swiper instance by HTML element

  • swiperEl - HTMLElement or string (with CSS Selector) of swiper container HTML element. Required.

For example:

  1. var swiper = app.swiper.create('.swiper-container', {
  2. speed: 400,
  3. spaceBetween: 100
  4. });

Swiper API (Parameters, Methods And Properties)

Сheck out Swiper API Website for the most relevant API parameters and methods.

Framework7’s version of Swiper doesn’t contain History and Hash Navigation modules

Swiper Auto Initialization

If you don’t need to use Swiper API and your Swiper is inside of the page and presented in DOM on moment of page initialization then it can be auto initialized with just adding additional swiper-init class:

  1. <!-- swiper-init to initialize swiper automatically -->
  2. <div class="swiper-container swiper-init">
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. ... other slides ...
  8. </div>
  9. </div>

In this case if you need to access created Swiper instance you can use the app.swiper.get app method:

  1. var swiper = app.swiper.get('.swiper-container');
  2. swiper.slideNext();

But what about Swiper parameters. In this case we need to pass them in data- attributes.

Parameters that used in camelCase, for example slidesPerView, in data- attributes should be used as kebab-case as data-slides-per-view

  1. <!-- swiper properties in data- attributes -->
  2. <div class="swiper-container swiper-init" data-speed="400" data-space-between="40">
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. ... other slides ...
  8. </div>
  9. </div>

Or we can pass all Swiper parameters in valid JSON format in data-swiper attribute:

  1. <!-- swiper properties in JSON format in data-swiper attribute -->
  2. <div class="swiper-container swiper-init" data-swiper='{"speed":"400", "spaceBetween":"40"}'>
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. ... other slides ...
  8. </div>
  9. </div>

Examples

  1. /* A bit of demo styles */
  2. .demo-swiper .swiper-slide {
  3. font-size: 25px;
  4. font-weight: 300;
  5. display: flex;
  6. justify-content: center;
  7. align-items: center;
  8. background: #fff;
  9. color: #000;
  10. }
  11. .demo-swiper .swiper-slide {
  12. box-sizing: border-box;
  13. border: 1px solid #ddd;
  14. background: #fff;
  15. }
  16. .demo-swiper {
  17. margin: 0px 0 35px;
  18. font-size: 18px;
  19. height: 120px;
  20. }
  21. .demo-swiper.demo-swiper-auto .swiper-slide {
  22. width: 85%;
  23. }
  24. .demo-swiper.demo-swiper-auto .swiper-slide:nth-child(2n) {
  25. width: 70%;
  26. }
  27. .demo-swiper.demo-swiper-auto .swiper-slide:nth-child(3n) {
  28. width: 30%;
  29. }

Default

  1. <div class="swiper-container swiper-init demo-swiper">
  2. <div class="swiper-wrapper">
  3. <div class="swiper-slide">Slide 1</div>
  4. <div class="swiper-slide">Slide 2</div>
  5. <div class="swiper-slide">Slide 3</div>
  6. <div class="swiper-slide">Slide 4</div>
  7. <div class="swiper-slide">Slide 5</div>
  8. <div class="swiper-slide">Slide 6</div>
  9. <div class="swiper-slide">Slide 7</div>
  10. <div class="swiper-slide">Slide 8</div>
  11. <div class="swiper-slide">Slide 9</div>
  12. <div class="swiper-slide">Slide 10</div>
  13. </div>
  14. </div>

1 Slide Per View, 50px Between

  1. <div data-pagination='{"el": ".swiper-pagination"}' data-space-between="50" class="swiper-container swiper-init demo-swiper">
  2. <div class="swiper-pagination"></div>
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. <div class="swiper-slide">Slide 4</div>
  8. <div class="swiper-slide">Slide 5</div>
  9. <div class="swiper-slide">Slide 6</div>
  10. <div class="swiper-slide">Slide 7</div>
  11. <div class="swiper-slide">Slide 8</div>
  12. <div class="swiper-slide">Slide 9</div>
  13. <div class="swiper-slide">Slide 10</div>
  14. </div>
  15. </div>

2 Slides Per View, 20px Between

  1. <div data-pagination='{"el": ".swiper-pagination"}' data-space-between="20" data-slides-per-view="2" class="swiper-container swiper-init demo-swiper">
  2. <div class="swiper-pagination"></div>
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. <div class="swiper-slide">Slide 4</div>
  8. <div class="swiper-slide">Slide 5</div>
  9. <div class="swiper-slide">Slide 6</div>
  10. <div class="swiper-slide">Slide 7</div>
  11. <div class="swiper-slide">Slide 8</div>
  12. <div class="swiper-slide">Slide 9</div>
  13. <div class="swiper-slide">Slide 10</div>
  14. </div>
  15. </div>

3 Slides Per View, 10px Between

  1. <div data-pagination='{"el": ".swiper-pagination"}' data-space-between="10" data-slides-per-view="3" class="swiper-container swiper-init demo-swiper">
  2. <div class="swiper-pagination"></div>
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. <div class="swiper-slide">Slide 4</div>
  8. <div class="swiper-slide">Slide 5</div>
  9. <div class="swiper-slide">Slide 6</div>
  10. <div class="swiper-slide">Slide 7</div>
  11. <div class="swiper-slide">Slide 8</div>
  12. <div class="swiper-slide">Slide 9</div>
  13. <div class="swiper-slide">Slide 10</div>
  14. </div>
  15. </div>

Auto Slides Per View + Centered

  1. <div data-pagination='{"el": ".swiper-pagination"}' data-space-between="10" data-slides-per-view="auto" data-centered-slides="true" class="swiper-container swiper-init demo-swiper demo-swiper-auto">
  2. <div class="swiper-pagination"></div>
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. <div class="swiper-slide">Slide 4</div>
  8. <div class="swiper-slide">Slide 5</div>
  9. <div class="swiper-slide">Slide 6</div>
  10. <div class="swiper-slide">Slide 7</div>
  11. <div class="swiper-slide">Slide 8</div>
  12. <div class="swiper-slide">Slide 9</div>
  13. <div class="swiper-slide">Slide 10</div>
  14. </div>
  15. </div>

Vertical, 10px Between

  1. <div data-pagination='{"el": ".swiper-pagination"}' data-space-between="10" data-direction="vertical" class="swiper-container swiper-init demo-swiper">
  2. <div class="swiper-pagination"></div>
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. <div class="swiper-slide">Slide 4</div>
  8. <div class="swiper-slide">Slide 5</div>
  9. </div>
  10. </div>

Slow speed

  1. <div data-speed="900" data-pagination='{"el": ".swiper-pagination"}' data-space-between="50" class="swiper-container swiper-init demo-swiper">
  2. <div class="swiper-pagination"></div>
  3. <div class="swiper-wrapper">
  4. <div class="swiper-slide">Slide 1</div>
  5. <div class="swiper-slide">Slide 2</div>
  6. <div class="swiper-slide">Slide 3</div>
  7. <div class="swiper-slide">Slide 4</div>
  8. <div class="swiper-slide">Slide 5</div>
  9. <div class="swiper-slide">Slide 6</div>
  10. <div class="swiper-slide">Slide 7</div>
  11. <div class="swiper-slide">Slide 8</div>
  12. <div class="swiper-slide">Slide 9</div>
  13. <div class="swiper-slide">Slide 10</div>
  14. </div>
  15. </div>

← Swipeout

Tabs →