@@ -83,8 +83,9 @@ const Autoplay = {
8383 swiper . autoplay . paused = false ;
8484 swiper . autoplay . run ( ) ;
8585 } else {
86- swiper . $wrapperEl [ 0 ] . addEventListener ( 'transitionend' , swiper . autoplay . onTransitionEnd ) ;
87- swiper . $wrapperEl [ 0 ] . addEventListener ( 'webkitTransitionEnd' , swiper . autoplay . onTransitionEnd ) ;
86+ [ 'transitionend' , 'webkitTransitionEnd' ] . forEach ( ( event ) => {
87+ swiper . $wrapperEl [ 0 ] . addEventListener ( event , swiper . autoplay . onTransitionEnd ) ;
88+ } ) ;
8889 }
8990 } ,
9091 onVisibilityChange ( ) {
@@ -102,18 +103,39 @@ const Autoplay = {
102103 const swiper = this ;
103104 if ( ! swiper || swiper . destroyed || ! swiper . $wrapperEl ) return ;
104105 if ( e . target !== swiper . $wrapperEl [ 0 ] ) return ;
105- swiper . $wrapperEl [ 0 ] . removeEventListener ( 'transitionend' , swiper . autoplay . onTransitionEnd ) ;
106- swiper . $wrapperEl [ 0 ] . removeEventListener (
107- 'webkitTransitionEnd' ,
108- swiper . autoplay . onTransitionEnd ,
109- ) ;
106+ [ 'transitionend' , 'webkitTransitionEnd' ] . forEach ( ( event ) => {
107+ swiper . $wrapperEl [ 0 ] . removeEventListener ( event , swiper . autoplay . onTransitionEnd ) ;
108+ } ) ;
110109 swiper . autoplay . paused = false ;
111110 if ( ! swiper . autoplay . running ) {
112111 swiper . autoplay . stop ( ) ;
113112 } else {
114113 swiper . autoplay . run ( ) ;
115114 }
116115 } ,
116+ onMouseEnter ( ) {
117+ const swiper = this ;
118+ swiper . autoplay . pause ( ) ;
119+ [ 'transitionend' , 'webkitTransitionEnd' ] . forEach ( ( event ) => {
120+ swiper . $wrapperEl [ 0 ] . removeEventListener ( event , swiper . autoplay . onTransitionEnd ) ;
121+ } ) ;
122+ } ,
123+ onMouseLeave ( ) {
124+ const swiper = this ;
125+ swiper . autoplay . run ( ) ;
126+ } ,
127+ attachMouseEvents ( ) {
128+ const swiper = this ;
129+ if ( swiper . params . autoplay . pauseOnMouseEnter ) {
130+ swiper . $el . on ( 'mouseenter' , swiper . autoplay . onMouseEnter ) ;
131+ swiper . $el . on ( 'mouseleave' , swiper . autoplay . onMouseLeave ) ;
132+ }
133+ } ,
134+ detachMouseEvents ( ) {
135+ const swiper = this ;
136+ swiper . $el . off ( 'mouseenter' , swiper . autoplay . onMouseEnter ) ;
137+ swiper . $el . off ( 'mouseleave' , swiper . autoplay . onMouseLeave ) ;
138+ } ,
117139} ;
118140
119141export default {
@@ -126,6 +148,7 @@ export default {
126148 disableOnInteraction : true ,
127149 stopOnLastSlide : false ,
128150 reverseDirection : false ,
151+ pauseOnMouseEnter : false ,
129152 } ,
130153 } ,
131154 create ( ) {
@@ -144,6 +167,7 @@ export default {
144167 swiper . autoplay . start ( ) ;
145168 const document = getDocument ( ) ;
146169 document . addEventListener ( 'visibilitychange' , swiper . autoplay . onVisibilityChange ) ;
170+ swiper . autoplay . attachMouseEvents ( ) ;
147171 }
148172 } ,
149173 beforeTransitionStart ( swiper , speed , internal ) {
@@ -174,6 +198,7 @@ export default {
174198 }
175199 } ,
176200 destroy ( swiper ) {
201+ swiper . autoplay . detachMouseEvents ( ) ;
177202 if ( swiper . autoplay . running ) {
178203 swiper . autoplay . stop ( ) ;
179204 }
0 commit comments