Skip to content

Commit 370f5ac

Browse files
committed
fix only one slide item loop
1 parent a3f96b8 commit 370f5ac

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

src/components/slide/slide.vue

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
if (this.showDots) {
120120
this._initDots()
121121
}
122+
if (this.currentPageIndex >= this.dots.length) {
123+
this.currentPageIndex = this.dots.length - 1
124+
}
122125
this._initSlide()
123126
124127
if (this.autoPlay) {
@@ -130,41 +133,24 @@
130133
this.slide.refresh()
131134
},
132135
_updateSlideDom(isResize) {
133-
if (this.direction === DIRECTION_H) {
134-
this._setSlideWidth(isResize)
135-
} else {
136-
this._setSlideHeight(isResize)
137-
}
138-
},
139-
_setSlideWidth(isResize) {
140-
this.children = this.$refs.slideGroup.children
141-
142-
let width = 0
143-
let slideWidth = this.$refs.slide.clientWidth
144-
for (let i = 0; i < this.children.length; i++) {
145-
let child = this.children[i]
146-
child.style.width = slideWidth + 'px'
147-
width += slideWidth
148-
}
149-
if (this.loop && !isResize) {
150-
width += 2 * slideWidth
151-
}
152-
this.$refs.slideGroup.style.width = width + 'px'
136+
this._setSlideStyle(isResize)
153137
},
154-
_setSlideHeight(isResize) {
138+
_setSlideStyle(isResize) {
155139
this.children = this.$refs.slideGroup.children
156140
157-
let height = 0
158-
let slideHeight = this.$refs.slide.clientHeight
159-
for (let i = 0; i < this.children.length; i++) {
160-
let child = this.children[i]
161-
child.style.height = slideHeight + 'px'
162-
height += slideHeight
141+
const target = this.direction === DIRECTION_H ? 'width' : 'height'
142+
let allSize = 0
143+
const slideSize = this.$refs.slide[`client${target[0].toUpperCase() + target.slice(1)}`]
144+
const len = this.children.length
145+
for (let i = 0; i < len; i++) {
146+
const child = this.children[i]
147+
child.style[target] = slideSize + 'px'
148+
allSize += slideSize
163149
}
164-
if (this.loop && !isResize) {
165-
height += 2 * slideHeight
150+
if (this.loop && !isResize && len > 1) {
151+
allSize += 2 * slideSize
166152
}
167-
this.$refs.slideGroup.style.height = height + 'px'
153+
this.$refs.slideGroup.style[target] = allSize + 'px'
168154
},
169155
_initSlide() {
170156
const eventPassthrough = this.direction === DIRECTION_H && this.allowVertical ? DIRECTION_V : ''

0 commit comments

Comments
 (0)