Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit 133763c

Browse files
author
Łukasz Florczak
committed
Autoplay & responsive settings
1 parent 665e703 commit 133763c

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

src/Agile.vue

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@
200200
// Prepare track
201201
this.el.track = this.$el.getElementsByClassName('agile__track')[0]
202202
203-
// Prepare autoplay
204-
if (this.settings.autoplay) {
205-
this.startAutoplay()
206-
}
207-
208203
// Windows resize listener
209204
window.addEventListener('resize', this.getWidth)
210205
@@ -221,21 +216,6 @@
221216
this.el.track.addEventListener('mouseup', this.handleMouseUp)
222217
this.el.track.addEventListener('mousemove', this.handleMouseMove)
223218
}
224-
225-
// Autoplay
226-
if (this.settings.autoplay) {
227-
if (this.settings.pauseOnHover) {
228-
this.el.track.addEventListener('mouseover', this.stopAutoplay)
229-
this.el.track.addEventListener('mouseout', this.startAutoplay)
230-
}
231-
232-
if (this.settings.pauseOnDotsHover) {
233-
for (let i = 0; i < this.slidesCount; ++i) {
234-
this.el.dots[i].addEventListener('mouseover', this.stopAutoplay)
235-
this.el.dots[i].addEventListener('mouseout', this.startAutoplay)
236-
}
237-
}
238-
}
239219
},
240220
241221
beforeDestroy () {
@@ -251,19 +231,7 @@
251231
this.el.track.removeEventListener('mousemove', this.handleMouseMove)
252232
}
253233
254-
if (this.settings.autoplay) {
255-
if (this.settings.pauseOnHover) {
256-
this.el.track.removeEventListener('mouseover', this.stopAutoplay)
257-
this.el.track.removeEventListener('mouseout', this.startAutoplay)
258-
}
259-
260-
if (this.settings.pauseOnDotsHover) {
261-
for (let i = 0; i < this.slidesCount; ++i) {
262-
this.el.dots[i].removeEventListener('mouseover', this.stopAutoplay)
263-
this.el.dots[i].removeEventListener('mouseout', this.startAutoplay)
264-
}
265-
}
266-
}
234+
this.disableAutoplayMode()
267235
},
268236
269237
methods: {
@@ -338,6 +306,39 @@
338306
this.countSlides()
339307
},
340308
309+
enableAutoplayMode () {
310+
// Autoplay
311+
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+
}
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)
321+
}
322+
}
323+
}
324+
},
325+
326+
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+
}
332+
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+
}
338+
}
339+
}
340+
},
341+
341342
countSlides () {
342343
if (this.settings.infinite && !this.settings.fade) {
343344
this.allSlidesCount = this.slidesCount + 2
@@ -488,6 +489,15 @@
488489
this.disableInfiniteMode()
489490
}
490491
492+
// Check autoplay mode status and enable/disable
493+
if (this.settings.autoplay) {
494+
this.enableAutoplayMode()
495+
this.startAutoplay()
496+
} else {
497+
this.stopAutoplay()
498+
this.disableAutoplayMode()
499+
}
500+
491501
// Actions on document resize
492502
for (let i = 0; i < this.allSlidesCount; ++i) {
493503
this.el.slides[i].style.width = this.width.container + 'px'

0 commit comments

Comments
 (0)