|
119 | 119 | if (this.showDots) { |
120 | 120 | this._initDots() |
121 | 121 | } |
| 122 | + if (this.currentPageIndex >= this.dots.length) { |
| 123 | + this.currentPageIndex = this.dots.length - 1 |
| 124 | + } |
122 | 125 | this._initSlide() |
123 | 126 |
|
124 | 127 | if (this.autoPlay) { |
|
130 | 133 | this.slide.refresh() |
131 | 134 | }, |
132 | 135 | _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) |
153 | 137 | }, |
154 | | - _setSlideHeight(isResize) { |
| 138 | + _setSlideStyle(isResize) { |
155 | 139 | this.children = this.$refs.slideGroup.children |
156 | 140 |
|
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 |
163 | 149 | } |
164 | | - if (this.loop && !isResize) { |
165 | | - height += 2 * slideHeight |
| 150 | + if (this.loop && !isResize && len > 1) { |
| 151 | + allSize += 2 * slideSize |
166 | 152 | } |
167 | | - this.$refs.slideGroup.style.height = height + 'px' |
| 153 | + this.$refs.slideGroup.style[target] = allSize + 'px' |
168 | 154 | }, |
169 | 155 | _initSlide() { |
170 | 156 | const eventPassthrough = this.direction === DIRECTION_H && this.allowVertical ? DIRECTION_V : '' |
|
0 commit comments