提交 16903150 编写于 作者: H hdx

swiper: 使用浮点计算

上级 1f8e77ee
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
}, },
onReady() { onReady() {
this.$headerHeight = (this.$refs["header"] as INode).offsetHeight this.$headerHeight = (this.$refs["header"] as INode).offsetHeight
this.$swiperWidth = (this.$refs["swiper"] as INode).offsetWidth this.$swiperWidth = (this.$refs["swiper"] as INode).getBoundingClientRect().width
this.queryTabItemsSize() this.queryTabItemsSize()
this.setSwiperIndex(0, true) this.setSwiperIndex(0, true)
}, },
...@@ -91,8 +91,8 @@ ...@@ -91,8 +91,8 @@
onSwiperTransition(e : SwiperTransitionEvent) { onSwiperTransition(e : SwiperTransitionEvent) {
const offsetX = e.detail.dx const offsetX = e.detail.dx
// 兼容微信 skyline 和 webview // 兼容微信 skyline 和 webview
const offsetIndex = Math.abs(offsetX.toInt()) == this.$swiperWidth ? 0 : offsetX / this.$swiperWidth const offsetIndex = offsetX.toInt() / this.$swiperWidth
const currentIndex = this.$animationFinishIndex + Math.abs(offsetIndex.toInt()) const currentIndex = this.$animationFinishIndex + offsetIndex.toInt()
let moveToIndex = offsetX > 0 ? currentIndex + 1 : currentIndex - 1 let moveToIndex = offsetX > 0 ? currentIndex + 1 : currentIndex - 1
if (moveToIndex < 0) { moveToIndex = 0 } if (moveToIndex < 0) { moveToIndex = 0 }
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
} }
}, },
onReady() { onReady() {
this.$swiperWidth = (this.$refs["swiper"] as INode).offsetWidth this.$swiperWidth = (this.$refs["swiper"] as INode).getBoundingClientRect().width
this.queryTabItemsSize() this.queryTabItemsSize()
this.setSwiperIndex(0, true) this.setSwiperIndex(0, true)
}, },
...@@ -66,8 +66,8 @@ ...@@ -66,8 +66,8 @@
onSwiperTransition(e : SwiperTransitionEvent) { onSwiperTransition(e : SwiperTransitionEvent) {
const offsetX = e.detail.dx const offsetX = e.detail.dx
// 兼容微信 skyline 和 webview // 兼容微信 skyline 和 webview
const offsetIndex = Math.abs(offsetX.toInt()) == this.$swiperWidth ? 0 : offsetX / this.$swiperWidth const offsetIndex = offsetX.toInt() / this.$swiperWidth
const currentIndex = this.$animationFinishIndex + Math.abs(offsetIndex.toInt()) const currentIndex = this.$animationFinishIndex + offsetIndex.toInt()
let moveToIndex = offsetX > 0 ? currentIndex + 1 : currentIndex - 1 let moveToIndex = offsetX > 0 ? currentIndex + 1 : currentIndex - 1
if (moveToIndex < 0) { moveToIndex = 0 } if (moveToIndex < 0) { moveToIndex = 0 }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册