|
195 | 195 | this.startAutoplay()
|
196 | 196 | }
|
197 | 197 |
|
198 |
| - // Listeners |
199 |
| - this.$nextTick(function () { |
200 |
| - // Windows resize listener |
201 |
| - window.addEventListener('resize', this.getWidth) |
202 |
| -
|
203 |
| - // Get width on start |
204 |
| - this.getWidth() |
205 |
| -
|
206 |
| - // Mouse and touch events |
207 |
| - if ('ontouchstart' in window) { |
208 |
| - this.el.track.addEventListener('touchstart', this.handleMouseDown) |
209 |
| - this.el.track.addEventListener('touchend', this.handleMouseUp) |
210 |
| - this.el.track.addEventListener('touchmove', this.handleMouseMove) |
211 |
| - } else { |
212 |
| - this.el.track.addEventListener('mousedown', this.handleMouseDown) |
213 |
| - this.el.track.addEventListener('mouseup', this.handleMouseUp) |
214 |
| - this.el.track.addEventListener('mousemove', this.handleMouseMove) |
215 |
| - } |
| 198 | + // Windows resize listener |
| 199 | + window.addEventListener('resize', this.getWidth) |
216 | 200 |
|
217 |
| - // Autoplay |
218 |
| - if (this.autoplay_) { |
219 |
| - if (this.pauseOnHover_) { |
220 |
| - this.el.track.addEventListener('mouseover', this.stopAutoplay) |
221 |
| - this.el.track.addEventListener('mouseout', this.startAutoplay) |
222 |
| - } |
| 201 | + // Get width on start |
| 202 | + this.getWidth() |
| 203 | +
|
| 204 | + // Mouse and touch events |
| 205 | + if ('ontouchstart' in window) { |
| 206 | + this.el.track.addEventListener('touchstart', this.handleMouseDown) |
| 207 | + this.el.track.addEventListener('touchend', this.handleMouseUp) |
| 208 | + this.el.track.addEventListener('touchmove', this.handleMouseMove) |
| 209 | + } else { |
| 210 | + this.el.track.addEventListener('mousedown', this.handleMouseDown) |
| 211 | + this.el.track.addEventListener('mouseup', this.handleMouseUp) |
| 212 | + this.el.track.addEventListener('mousemove', this.handleMouseMove) |
| 213 | + } |
223 | 214 |
|
224 |
| - if (this.pauseOnDotsHover_) { |
225 |
| - for (let i = 0; i < this.slidesCount; ++i) { |
226 |
| - this.el.dots[i].addEventListener('mouseover', this.stopAutoplay) |
227 |
| - this.el.dots[i].addEventListener('mouseout', this.startAutoplay) |
228 |
| - } |
| 215 | + // Autoplay |
| 216 | + if (this.autoplay_) { |
| 217 | + if (this.pauseOnHover_) { |
| 218 | + this.el.track.addEventListener('mouseover', this.stopAutoplay) |
| 219 | + this.el.track.addEventListener('mouseout', this.startAutoplay) |
| 220 | + } |
| 221 | +
|
| 222 | + if (this.pauseOnDotsHover_) { |
| 223 | + for (let i = 0; i < this.slidesCount; ++i) { |
| 224 | + this.el.dots[i].addEventListener('mouseover', this.stopAutoplay) |
| 225 | + this.el.dots[i].addEventListener('mouseout', this.startAutoplay) |
229 | 226 | }
|
230 | 227 | }
|
231 |
| - }) |
| 228 | + } |
232 | 229 | },
|
233 | 230 |
|
234 | 231 | beforeDestroy () {
|
235 | 232 | window.removeEventListener('resize', this.getWidth)
|
236 | 233 |
|
237 | 234 | if ('ontouchstart' in window) {
|
238 |
| - this.el.track.removeEventListener('touchstart') |
239 |
| - this.el.track.removeEventListener('touchend') |
240 |
| - this.el.track.removeEventListener('touchmove') |
| 235 | + this.el.track.removeEventListener('touchstart', this.handleMouseDown) |
| 236 | + this.el.track.removeEventListener('touchend', this.handleMouseUp) |
| 237 | + this.el.track.removeEventListener('touchmove', this.handleMouseMove) |
241 | 238 | } else {
|
242 |
| - this.el.track.removeEventListener('mousedown') |
243 |
| - this.el.track.removeEventListener('mouseup') |
244 |
| - this.el.track.removeEventListener('mousemove') |
| 239 | + this.el.track.removeEventListener('mousedown', this.handleMouseDown) |
| 240 | + this.el.track.removeEventListener('mouseup', this.handleMouseUp) |
| 241 | + this.el.track.removeEventListener('mousemove', this.handleMouseMove) |
245 | 242 | }
|
246 | 243 |
|
247 | 244 | if (this.autoplay_) {
|
248 | 245 | if (this.pauseOnHover_) {
|
249 |
| - this.el.track.removeEventListener('mouseover') |
250 |
| - this.el.track.removeEventListener('mouseout') |
| 246 | + this.el.track.removeEventListener('mouseover', this.stopAutoplay) |
| 247 | + this.el.track.removeEventListener('mouseout', this.startAutoplay) |
251 | 248 | }
|
252 | 249 |
|
253 | 250 | if (this.pauseOnDotsHover_) {
|
254 | 251 | for (let i = 0; i < this.slidesCount; ++i) {
|
255 |
| - this.el.dots[i].removeEventListener('mouseover') |
256 |
| - this.el.dots[i].removeEventListener('mouseout') |
| 252 | + this.el.dots[i].removeEventListener('mouseover', this.stopAutoplay) |
| 253 | + this.el.dots[i].removeEventListener('mouseout', this.startAutoplay) |
257 | 254 | }
|
258 | 255 | }
|
259 | 256 | }
|
|
0 commit comments