Skip to content

Commit f24bef9

Browse files
author
lixichen
committed
fix 优化 #67
1 parent fa3023c commit f24bef9

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

dist/build.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/build.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/demo/build.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/demo/module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-concise-slider",
3-
"version": "3.3.5",
3+
"version": "3.3.6",
44
"repository": {
55
"type": "git",
66
"url": "git@github.com/warpcgd/vue-concise-slider.git"

src/components/slider.vue

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,7 @@ export default {
292292
this.clock().begin(that)
293293
}
294294
// 解决页面切换报错bug
295-
document.addEventListener('visibilitychange', function () {
296-
if (document.hidden) {
297-
that.options.autoplay && that.clock().stop(that)
298-
} else {
299-
that.options.autoplay && that.clock().begin(that)
300-
}
301-
}, false)
295+
document.addEventListener('visibilitychange', this.visibilitychange, false)
302296
// 设定垂直轮播class
303297
if (this.options.direction === 'vertical') {
304298
this.s_data.containerClass['swiper-container-vertical'] = true
@@ -307,33 +301,36 @@ export default {
307301
}
308302
// 添加reszie监听
309303
if (this.s_data.resize) {
310-
window.addEventListener('resize', () => {
311-
this.s_data.pageWidth = this.$el.offsetWidth
312-
this.s_data.pageHeight = this.$el.offsetHeight
313-
// 修复循环切换bug
314-
if (this.data.currentPage >= this.s_data.sliderLength && that.options.loop) {
315-
this.slide(0, 'animationnone')
316-
return false
317-
}
318-
this.slide(this.data.currentPage, 'animationnone')
319-
})
304+
window.addEventListener('resize', this.resize)
320305
}
321306
},
322307
beforeDestroy () {
323-
let that = this
324308
this.options.autoplay && this.clock().stop(this)
325309
if (this.options.preventDocumentMove === true) {
326310
document.removeEventListener('touchmove', this.preventDefault())
327311
}
328-
document.removeEventListener('visibilitychange', function () {
312+
document.removeEventListener('visibilitychange', this.visibilitychange, false)
313+
window.removeEventListener('resize', this.resize)
314+
},
315+
methods: {
316+
visibilitychange () {
317+
let that = this
329318
if (document.hidden) {
330319
that.options.autoplay && that.clock().stop(that)
331320
} else {
332321
that.options.autoplay && that.clock().begin(that)
333322
}
334-
}, false)
335-
},
336-
methods: {
323+
},
324+
resize () {
325+
this.s_data.pageWidth = this.$el.offsetWidth
326+
this.s_data.pageHeight = this.$el.offsetHeight
327+
// 修复循环切换bug
328+
if (this.data.currentPage >= this.s_data.sliderLength && this.options.loop) {
329+
this.slide(0, 'animationnone')
330+
return false
331+
}
332+
this.slide(this.data.currentPage, 'animationnone')
333+
},
337334
swipeStart (e) {
338335
let that = this
339336
this.s_data.e = e

0 commit comments

Comments
 (0)