@@ -19,6 +19,13 @@ export default function Thumb({ swiper, extendParams, on }) {
1919 swiper : null ,
2020 } ;
2121
22+ function isVirtualEnabled ( ) {
23+ const thumbsSwiper = swiper . thumbs . swiper ;
24+ if ( ! thumbsSwiper || thumbsSwiper . destroyed ) return false ;
25+
26+ return thumbsSwiper . params . virtual && thumbsSwiper . params . virtual . enabled ;
27+ }
28+
2229 function onThumbClick ( ) {
2330 const thumbsSwiper = swiper . thumbs . swiper ;
2431 if ( ! thumbsSwiper || thumbsSwiper . destroyed ) return ;
@@ -76,18 +83,20 @@ export default function Thumb({ swiper, extendParams, on }) {
7683 }
7784 swiper . thumbs . swiper . el . classList . add ( swiper . params . thumbs . thumbsContainerClass ) ;
7885 swiper . thumbs . swiper . on ( 'tap' , onThumbClick ) ;
86+
87+ if ( isVirtualEnabled ( ) ) {
88+ swiper . thumbs . swiper . on ( 'virtualUpdate' , ( ) => {
89+ update ( false , { autoScroll : false } ) ;
90+ } ) ;
91+ }
92+
7993 return true ;
8094 }
8195
82- function update ( initial ) {
96+ function update ( initial , p = { autoScroll : true } ) {
8397 const thumbsSwiper = swiper . thumbs . swiper ;
8498 if ( ! thumbsSwiper || thumbsSwiper . destroyed ) return ;
8599
86- const slidesPerView =
87- thumbsSwiper . params . slidesPerView === 'auto'
88- ? thumbsSwiper . slidesPerViewDynamic ( )
89- : thumbsSwiper . params . slidesPerView ;
90-
91100 // Activate thumbs
92101 let thumbsToActivate = 1 ;
93102 const thumbActiveClass = swiper . params . thumbs . slideThumbActiveClass ;
@@ -103,10 +112,7 @@ export default function Thumb({ swiper, extendParams, on }) {
103112 thumbsToActivate = Math . floor ( thumbsToActivate ) ;
104113
105114 thumbsSwiper . slides . forEach ( ( slideEl ) => slideEl . classList . remove ( thumbActiveClass ) ) ;
106- if (
107- thumbsSwiper . params . loop ||
108- ( thumbsSwiper . params . virtual && thumbsSwiper . params . virtual . enabled )
109- ) {
115+ if ( thumbsSwiper . params . loop || isVirtualEnabled ( ) ) {
110116 for ( let i = 0 ; i < thumbsToActivate ; i += 1 ) {
111117 elementChildren (
112118 thumbsSwiper . slidesEl ,
@@ -123,6 +129,20 @@ export default function Thumb({ swiper, extendParams, on }) {
123129 }
124130 }
125131
132+ if ( p . autoScroll ) {
133+ autoScroll ( initial ? 0 : undefined ) ;
134+ }
135+ }
136+
137+ function autoScroll ( slideSpeed ) {
138+ const thumbsSwiper = swiper . thumbs . swiper ;
139+ if ( ! thumbsSwiper || thumbsSwiper . destroyed ) return ;
140+
141+ const slidesPerView =
142+ thumbsSwiper . params . slidesPerView === 'auto'
143+ ? thumbsSwiper . slidesPerViewDynamic ( )
144+ : thumbsSwiper . params . slidesPerView ;
145+
126146 const autoScrollOffset = swiper . params . thumbs . autoScrollOffset ;
127147 const useOffset = autoScrollOffset && ! thumbsSwiper . params . loop ;
128148 if ( swiper . realIndex !== thumbsSwiper . realIndex || useOffset ) {
@@ -160,7 +180,7 @@ export default function Thumb({ swiper, extendParams, on }) {
160180 ) {
161181 // newThumbsIndex = newThumbsIndex - slidesPerView + 1;
162182 }
163- thumbsSwiper . slideTo ( newThumbsIndex , initial ? 0 : undefined ) ;
183+ thumbsSwiper . slideTo ( newThumbsIndex , slideSpeed ) ;
164184 }
165185 }
166186 }
0 commit comments