提交 318c7a05 编写于 作者: D DCloud_LXH

chore(h5): swiper mouseEvent

上级 5f6a7a13
...@@ -167,10 +167,13 @@ export default { ...@@ -167,10 +167,13 @@ export default {
displayMultipleItemsNumber () { displayMultipleItemsNumber () {
this._resetLayout() this._resetLayout()
}, },
navigation (val) { navigation: {
this.isNavigationAuto = val === 'auto' immediate: true,
this.hideNavigation = val !== true || this.isNavigationAuto handler (val) {
this._navigationSwiperAddMouseEvent() this.isNavigationAuto = val === 'auto'
this.hideNavigation = val !== true || this.isNavigationAuto
this._navigationSwiperAddMouseEvent()
}
}, },
items () { items () {
this._setNavigationState() this._setNavigationState()
...@@ -659,6 +662,8 @@ export default { ...@@ -659,6 +662,8 @@ export default {
this._onSwiperDotClick(_current) this._onSwiperDotClick(_current)
}, },
_navigationMouseMove (e) { _navigationMouseMove (e) {
clearTimeout(this.hideNavigationTimer)
const { clientX, clientY } = e const { clientX, clientY } = e
const { const {
left, left,
...@@ -669,15 +674,20 @@ export default { ...@@ -669,15 +674,20 @@ export default {
height height
} = this.$refs.slidesWrapper.getBoundingClientRect() } = this.$refs.slidesWrapper.getBoundingClientRect()
let hide = false
if (this.vertical) { if (this.vertical) {
this.hideNavigation = !( hide = !(clientY - top < height / 3 || bottom - clientY < height / 3)
clientY - top < height / 3 || bottom - clientY < height / 3
)
} else { } else {
this.hideNavigation = !( hide = !(clientX - left < width / 3 || right - clientX < width / 3)
clientX - left < width / 3 || right - clientX < width / 3 }
)
if (hide) {
return this.hideNavigationTimer = setTimeout(() => {
this.hideNavigation = hide
}, 300)
} }
this.hideNavigation = hide
}, },
_navigationMouseOut () { _navigationMouseOut () {
this.hideNavigation = true this.hideNavigation = true
...@@ -687,11 +697,11 @@ export default { ...@@ -687,11 +697,11 @@ export default {
const rootRef = this.$refs.slidesWrapper const rootRef = this.$refs.slidesWrapper
if (rootRef) { if (rootRef) {
rootRef.removeEventListener('mousemove', this._navigationMouseMove) rootRef.removeEventListener('mousemove', this._navigationMouseMove)
rootRef.removeEventListener('mouseout', this._navigationMouseOut) rootRef.removeEventListener('mouseleave', this._navigationMouseOut)
if (this.isNavigationAuto) { if (this.isNavigationAuto) {
rootRef.addEventListener('mousemove', this._navigationMouseMove) rootRef.addEventListener('mousemove', this._navigationMouseMove)
rootRef.addEventListener('mouseout', this._navigationMouseOut) rootRef.addEventListener('mouseleave', this._navigationMouseOut)
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册