|
113 | 113 | slides: null
|
114 | 114 | },
|
115 | 115 | slidesCount: 0,
|
| 116 | + autoplayStatus: false, |
116 | 117 | autoplayTimeout: null,
|
117 | 118 | allSlidesCount: 0,
|
118 | 119 | currentSlide: 0,
|
|
164 | 165 |
|
165 | 166 | // Set first load settings
|
166 | 167 | Object.assign(this.settings, this.defaultSettings)
|
167 |
| -
|
168 |
| - // Protection against contradictory settings |
169 |
| - if (this.settings.autoplay) { |
170 |
| - this.settings.infinite = true |
171 |
| - } |
172 |
| -
|
173 |
| - if (this.settings.pauseOnDotsHover) { |
174 |
| - this.settings.dots = true |
175 |
| - } |
176 | 168 | },
|
177 | 169 |
|
178 | 170 | mounted () {
|
|
307 | 299 | },
|
308 | 300 |
|
309 | 301 | enableAutoplayMode () {
|
310 |
| - // Autoplay |
| 302 | + // Protection against contradictory settings |
311 | 303 | if (this.settings.autoplay) {
|
312 |
| - if (this.settings.pauseOnHover) { |
313 |
| - this.el.track.addEventListener('mouseover', this.stopAutoplay) |
314 |
| - this.el.track.addEventListener('mouseout', this.startAutoplay) |
315 |
| - } |
| 304 | + this.settings.infinite = true |
| 305 | + } |
316 | 306 |
|
317 |
| - if (this.settings.pauseOnDotsHover) { |
318 |
| - for (let i = 0; i < this.slidesCount; ++i) { |
319 |
| - this.el.dots[i].addEventListener('mouseover', this.stopAutoplay) |
320 |
| - this.el.dots[i].addEventListener('mouseout', this.startAutoplay) |
321 |
| - } |
| 307 | + if (this.settings.pauseOnDotsHover) { |
| 308 | + this.settings.dots = true |
| 309 | + } |
| 310 | +
|
| 311 | + // Autoplay |
| 312 | + if (this.settings.pauseOnHover) { |
| 313 | + this.el.track.addEventListener('mouseover', this.stopAutoplay) |
| 314 | + this.el.track.addEventListener('mouseout', this.startAutoplay) |
| 315 | + } |
| 316 | +
|
| 317 | + if (this.settings.pauseOnDotsHover) { |
| 318 | + for (let i = 0; i < this.slidesCount; ++i) { |
| 319 | + this.el.dots[i].addEventListener('mouseover', this.stopAutoplay) |
| 320 | + this.el.dots[i].addEventListener('mouseout', this.startAutoplay) |
322 | 321 | }
|
323 | 322 | }
|
| 323 | +
|
| 324 | + this.autoplayStatus = true |
| 325 | + this.startAutoplay() |
324 | 326 | },
|
325 | 327 |
|
326 | 328 | disableAutoplayMode () {
|
327 |
| - if (this.settings.autoplay) { |
328 |
| - if (this.settings.pauseOnHover) { |
329 |
| - this.el.track.removeEventListener('mouseover', this.stopAutoplay) |
330 |
| - this.el.track.removeEventListener('mouseout', this.startAutoplay) |
331 |
| - } |
| 329 | + if (this.settings.pauseOnHover) { |
| 330 | + this.el.track.removeEventListener('mouseover', this.stopAutoplay) |
| 331 | + this.el.track.removeEventListener('mouseout', this.startAutoplay) |
| 332 | + } |
332 | 333 |
|
333 |
| - if (this.settings.pauseOnDotsHover) { |
334 |
| - for (let i = 0; i < this.slidesCount; ++i) { |
335 |
| - this.el.dots[i].removeEventListener('mouseover', this.stopAutoplay) |
336 |
| - this.el.dots[i].removeEventListener('mouseout', this.startAutoplay) |
337 |
| - } |
| 334 | + if (this.settings.pauseOnDotsHover) { |
| 335 | + for (let i = 0; i < this.slidesCount; ++i) { |
| 336 | + this.el.dots[i].removeEventListener('mouseover', this.stopAutoplay) |
| 337 | + this.el.dots[i].removeEventListener('mouseout', this.startAutoplay) |
338 | 338 | }
|
339 | 339 | }
|
| 340 | +
|
| 341 | + this.autoplayStatus = false |
| 342 | + this.stopAutoplay() |
340 | 343 | },
|
341 | 344 |
|
342 | 345 | countSlides () {
|
|
365 | 368 |
|
366 | 369 | startAutoplay () {
|
367 | 370 | this.autoplayTimeout = setTimeout(() => {
|
| 371 | + if (!this.settings.autoplay) { |
| 372 | + this.stopAutoplay() |
| 373 | + this.disableAutoplayMode() |
| 374 | + this.autoplayStatus = false |
| 375 | + return false |
| 376 | + } |
| 377 | +
|
368 | 378 | this.nextSlide()
|
369 | 379 | }, this.autoplaySpeed)
|
370 | 380 | },
|
|
490 | 500 | }
|
491 | 501 |
|
492 | 502 | // Check autoplay mode status and enable/disable
|
493 |
| - if (this.settings.autoplay) { |
| 503 | + if (this.settings.autoplay && !this.autoplayStatus) { |
494 | 504 | this.enableAutoplayMode()
|
495 |
| - this.startAutoplay() |
496 |
| - } else { |
497 |
| - this.stopAutoplay() |
| 505 | + } |
| 506 | +
|
| 507 | + if (!this.settings.autoplay && this.autoplayStatus) { |
498 | 508 | this.disableAutoplayMode()
|
499 | 509 | }
|
500 | 510 |
|
|
0 commit comments