UNPKG

1.27 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.default = updateAutoHeight;
5
6function updateAutoHeight(speed) {
7 var swiper = this;
8 var activeSlides = [];
9 var newHeight = 0;
10 var i;
11
12 if (typeof speed === 'number') {
13 swiper.setTransition(speed);
14 } else if (speed === true) {
15 swiper.setTransition(swiper.params.speed);
16 } // Find slides currently in view
17
18
19 if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
20 if (swiper.params.centeredSlides) {
21 swiper.visibleSlides.each(function (slide) {
22 activeSlides.push(slide);
23 });
24 } else {
25 for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
26 var index = swiper.activeIndex + i;
27 if (index > swiper.slides.length) break;
28 activeSlides.push(swiper.slides.eq(index)[0]);
29 }
30 }
31 } else {
32 activeSlides.push(swiper.slides.eq(swiper.activeIndex)[0]);
33 } // Find new height from highest slide in view
34
35
36 for (i = 0; i < activeSlides.length; i += 1) {
37 if (typeof activeSlides[i] !== 'undefined') {
38 var height = activeSlides[i].offsetHeight;
39 newHeight = height > newHeight ? height : newHeight;
40 }
41 } // Update Height
42
43
44 if (newHeight) swiper.$wrapperEl.css('height', newHeight + "px");
45}
\No newline at end of file