1 | import $ from '../../shared/dom.js';
|
2 | export default function updateAutoHeight(speed) {
|
3 | const swiper = this;
|
4 | const activeSlides = [];
|
5 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
6 | let newHeight = 0;
|
7 | let i;
|
8 |
|
9 | if (typeof speed === 'number') {
|
10 | swiper.setTransition(speed);
|
11 | } else if (speed === true) {
|
12 | swiper.setTransition(swiper.params.speed);
|
13 | }
|
14 |
|
15 | const getSlideByIndex = index => {
|
16 | if (isVirtual) {
|
17 | return swiper.slides.filter(el => parseInt(el.getAttribute('data-swiper-slide-index'), 10) === index)[0];
|
18 | }
|
19 |
|
20 | return swiper.slides.eq(index)[0];
|
21 | };
|
22 |
|
23 |
|
24 | if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
|
25 | if (swiper.params.centeredSlides) {
|
26 | (swiper.visibleSlides || $([])).each(slide => {
|
27 | activeSlides.push(slide);
|
28 | });
|
29 | } else {
|
30 | for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
|
31 | const index = swiper.activeIndex + i;
|
32 | if (index > swiper.slides.length && !isVirtual) break;
|
33 | activeSlides.push(getSlideByIndex(index));
|
34 | }
|
35 | }
|
36 | } else {
|
37 | activeSlides.push(getSlideByIndex(swiper.activeIndex));
|
38 | }
|
39 |
|
40 |
|
41 | for (i = 0; i < activeSlides.length; i += 1) {
|
42 | if (typeof activeSlides[i] !== 'undefined') {
|
43 | const height = activeSlides[i].offsetHeight;
|
44 | newHeight = height > newHeight ? height : newHeight;
|
45 | }
|
46 | }
|
47 |
|
48 |
|
49 | if (newHeight || newHeight === 0) swiper.$wrapperEl.css('height', `${newHeight}px`);
|
50 | } |
\ | No newline at end of file |