From 370f5aca7eec12c520a73a7e62e5159d129f37c5 Mon Sep 17 00:00:00 2001 From: dolymood Date: Mon, 9 Apr 2018 17:11:26 +0800 Subject: [PATCH] fix only one slide item loop --- src/components/slide/slide.vue | 46 ++++++++++++---------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/components/slide/slide.vue b/src/components/slide/slide.vue index 92f9b670..b64c3848 100644 --- a/src/components/slide/slide.vue +++ b/src/components/slide/slide.vue @@ -119,6 +119,9 @@ if (this.showDots) { this._initDots() } + if (this.currentPageIndex >= this.dots.length) { + this.currentPageIndex = this.dots.length - 1 + } this._initSlide() if (this.autoPlay) { @@ -130,41 +133,24 @@ this.slide.refresh() }, _updateSlideDom(isResize) { - if (this.direction === DIRECTION_H) { - this._setSlideWidth(isResize) - } else { - this._setSlideHeight(isResize) - } - }, - _setSlideWidth(isResize) { - this.children = this.$refs.slideGroup.children - - let width = 0 - let slideWidth = this.$refs.slide.clientWidth - for (let i = 0; i < this.children.length; i++) { - let child = this.children[i] - child.style.width = slideWidth + 'px' - width += slideWidth - } - if (this.loop && !isResize) { - width += 2 * slideWidth - } - this.$refs.slideGroup.style.width = width + 'px' + this._setSlideStyle(isResize) }, - _setSlideHeight(isResize) { + _setSlideStyle(isResize) { this.children = this.$refs.slideGroup.children - let height = 0 - let slideHeight = this.$refs.slide.clientHeight - for (let i = 0; i < this.children.length; i++) { - let child = this.children[i] - child.style.height = slideHeight + 'px' - height += slideHeight + const target = this.direction === DIRECTION_H ? 'width' : 'height' + let allSize = 0 + const slideSize = this.$refs.slide[`client${target[0].toUpperCase() + target.slice(1)}`] + const len = this.children.length + for (let i = 0; i < len; i++) { + const child = this.children[i] + child.style[target] = slideSize + 'px' + allSize += slideSize } - if (this.loop && !isResize) { - height += 2 * slideHeight + if (this.loop && !isResize && len > 1) { + allSize += 2 * slideSize } - this.$refs.slideGroup.style.height = height + 'px' + this.$refs.slideGroup.style[target] = allSize + 'px' }, _initSlide() { const eventPassthrough = this.direction === DIRECTION_H && this.allowVertical ? DIRECTION_V : '' -- GitLab