File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
src/components/core/update Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
1
export default function updateAutoHeight ( speed ) {
2
2
const swiper = this ;
3
3
const activeSlides = [ ] ;
4
+ const isVirtual = swiper . virtual && swiper . params . virtual . enabled ;
4
5
let newHeight = 0 ;
5
6
let i ;
6
7
if ( typeof speed === 'number' ) {
7
8
swiper . setTransition ( speed ) ;
8
9
} else if ( speed === true ) {
9
10
swiper . setTransition ( swiper . params . speed ) ;
10
11
}
12
+
13
+ const getSlideByIndex = ( index ) => {
14
+ if ( isVirtual ) {
15
+ return swiper . slides . filter (
16
+ ( el ) => parseInt ( el . getAttribute ( 'data-swiper-slide-index' ) , 10 ) === index ,
17
+ ) [ 0 ] ;
18
+ }
19
+ return swiper . slides . eq ( index ) [ 0 ] ;
20
+ } ;
11
21
// Find slides currently in view
12
22
if ( swiper . params . slidesPerView !== 'auto' && swiper . params . slidesPerView > 1 ) {
13
23
if ( swiper . params . centeredSlides ) {
@@ -17,12 +27,12 @@ export default function updateAutoHeight(speed) {
17
27
} else {
18
28
for ( i = 0 ; i < Math . ceil ( swiper . params . slidesPerView ) ; i += 1 ) {
19
29
const index = swiper . activeIndex + i ;
20
- if ( index > swiper . slides . length ) break ;
21
- activeSlides . push ( swiper . slides . eq ( index ) [ 0 ] ) ;
30
+ if ( index > swiper . slides . length && ! isVirtual ) break ;
31
+ activeSlides . push ( getSlideByIndex ( index ) ) ;
22
32
}
23
33
}
24
34
} else {
25
- activeSlides . push ( swiper . slides . eq ( swiper . activeIndex ) [ 0 ] ) ;
35
+ activeSlides . push ( getSlideByIndex ( swiper . activeIndex ) ) ;
26
36
}
27
37
28
38
// Find new height from highest slide in view
You can’t perform that action at this time.
0 commit comments