提交 72b529b9 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

fix: button navigator view hover-class 兼容鼠标事件

上级 89184583
...@@ -130,6 +130,8 @@ export default { ...@@ -130,6 +130,8 @@ export default {
touchstart: this._hoverTouchStart, touchstart: this._hoverTouchStart,
touchend: this._hoverTouchEnd, touchend: this._hoverTouchEnd,
touchcancel: this._hoverTouchCancel, touchcancel: this._hoverTouchCancel,
mousedown: this._hoverMousedown,
mouseup: this._hoverMouseup,
click: this._onClick click: this._onClick
} }
}, },
...@@ -429,4 +431,4 @@ export default { ...@@ -429,4 +431,4 @@ export default {
border-color: rgba(230, 67, 64, 0.6); border-color: rgba(230, 67, 64, 0.6);
background-color: transparent; background-color: transparent;
} }
</style> </style>
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@touchstart="_hoverTouchStart" @touchstart="_hoverTouchStart"
@touchend="_hoverTouchEnd" @touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel" @touchcancel="_hoverTouchCancel"
@mousedown="_hoverMousedown"
@mouseup="_hoverMouseup"
@click="_onClick" @click="_onClick"
v-on="$listeners" v-on="$listeners"
> >
......
...@@ -4,6 +4,7 @@ export default { ...@@ -4,6 +4,7 @@ export default {
hovering: false hovering: false
} }
}, },
props: { props: {
hoverClass: { hoverClass: {
type: String, type: String,
...@@ -22,8 +23,22 @@ export default { ...@@ -22,8 +23,22 @@ export default {
default: 400 default: 400
} }
}, },
methods: { methods: {
_hoverTouchStart (evt) { _hoverTouchStart (evt) {
if (evt.touches.length > 1) {
return
}
this._handleHoverStart(evt)
},
_hoverMousedown (evt) {
evt.preventDefault()
this._handleHoverStart(evt)
window.addEventListener('mouseup', this._hoverMouseup)
},
_handleHoverStart (evt) {
// TODO detect scrolling // TODO detect scrolling
if (evt._hoverPropagationStopped) { if (evt._hoverPropagationStopped) {
return return
...@@ -31,9 +46,6 @@ export default { ...@@ -31,9 +46,6 @@ export default {
if (!this.hoverClass || this.hoverClass === 'none' || this.disabled) { if (!this.hoverClass || this.hoverClass === 'none' || this.disabled) {
return return
} }
if (evt.touches.length > 1) {
return
}
if (this.hoverStopPropagation) { if (this.hoverStopPropagation) {
evt._hoverPropagationStopped = true evt._hoverPropagationStopped = true
} }
...@@ -45,12 +57,23 @@ export default { ...@@ -45,12 +57,23 @@ export default {
} }
}, this.hoverStartTime) }, this.hoverStartTime)
}, },
_hoverTouchEnd (evt) {
_hoverMouseup () {
this._handleHoverEnd()
window.removeEventListener('mouseup', this._hoverMouseup)
},
_hoverTouchEnd () {
this._handleHoverEnd()
},
_handleHoverEnd () {
this._hoverTouch = false this._hoverTouch = false
if (this.hovering) { if (this.hovering) {
this._hoverReset() this._hoverReset()
} }
}, },
_hoverReset () { _hoverReset () {
requestAnimationFrame(() => { requestAnimationFrame(() => {
clearTimeout(this._hoverStayTimer) clearTimeout(this._hoverStayTimer)
...@@ -59,10 +82,11 @@ export default { ...@@ -59,10 +82,11 @@ export default {
}, this.hoverStayTime) }, this.hoverStayTime)
}) })
}, },
_hoverTouchCancel (evt) {
_hoverTouchCancel () {
this._hoverTouch = false this._hoverTouch = false
this.hovering = false this.hovering = false
clearTimeout(this._hoverStartTimer) clearTimeout(this._hoverStartTimer)
} }
} }
} }
...@@ -5,13 +5,15 @@ ...@@ -5,13 +5,15 @@
@touchstart="_hoverTouchStart" @touchstart="_hoverTouchStart"
@touchend="_hoverTouchEnd" @touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel" @touchcancel="_hoverTouchCancel"
@mousedown="_hoverMousedown"
@mouseup="_hoverMouseup"
v-on="$listeners" v-on="$listeners"
> >
<slot /> <slot />
</uni-view> </uni-view>
<uni-view <uni-view
v-else v-else
v-on="$listeners" v-on="$listeners"
> >
<slot /> <slot />
</uni-view> </uni-view>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册