any86 / Notes

:rocket: 笔记
https://github.com/any86/Notes/issues
28 stars 9 forks source link

关于touchstart做了"阻止默认", 那么mousedown等后续事件就不触发了. #94

Open any86 opened 2 years ago

any86 commented 2 years ago

https://codesandbox.io/s/charming-beaver-qq4ozv?file=/src/components/HelloWorld.vue

移动端会触发mouse事件, 这个是我之前不知道的, 所以我的手势库在"不阻止默认"的情况下, 在手机上touch/mouse都会触发. 如果touchstart内阻止默认了, 那么mouse相关事件都不会触发了.

这里只是记录, 稍后版本要做些兼容


    this.$el.addEventListener('touchstart', e=>{
      e.preventDefault();
    })

    this.$el.addEventListener('mousedown', e=>{
      e.preventDefault();
    })

    this.$el.addEventListener('mouseup', e=>{
      alert(e.type)
    })