zoukankan      html  css  js  c++  java
  • vue中touchEnd事件和touchStart、touchMove获取坐标不一样,IOS绑定touch事件失效

    touchEnd    ~~~~~~~~~~~~~~~~   e.changedTouches[0].pageY

    touchStart    ~~~~~~~~~~~~~~~~   e.targetTouches[0].pageY

    touchMove    ~~~~~~~~~~~~~~~~   e.changedTouches[0].pageY

     1 activated() {
     2     this.listenerFunction()
     3   },
     4 destroyed() {
     5     window.removeEventListener('scroll', this.listenerFunction)
     6   },
     7 methods{
     8     scrollBottom() {
     9       const windowHeight = window.screen.height
    10       const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
    11       const contentHeight = this.$refs.scoreMallContainer.clientHeight
    12       const toBottom = contentHeight - windowHeight - scrollTop
    13       this.toBottom = toBottom
    14     },
    15     touchstart(e) {
    16       this.startPageY = e.targetTouches[0].pageY
    17     },
    18     touchend(e) {
    19       this.endPageY = e.changedTouches[0].pageY
    20       if (!this.toBottom && this.endPageY - this.startPageY < 0) {
    21         if (!this.$refs.taskView.popup) {
    22           this.$refs.taskView.popupSwich()
    23         }
    24       }
    25     },
    26 }
    1  popupSwich() {
    2       this.popup = !this.popup
    3       const taskBoxStyle = this.$refs.taskBox.style
    4       this.popup ? taskBoxStyle.overflow = 'scroll' : taskBoxStyle.overflow = 'hidden'
    5     },

    不止是iOS,chrome等浏览器均存在类似问题,原因在于其在实现时的一点小改动: 浏览器只有在执行事件处理函数后才能知道有没有触发preventDefault,故页面会有延迟。为了解决这种延迟,从而让页面滚动的效果如丝般顺滑,从 chrome56 开始,在 window、document 和 body 上注册的 touchstart 和 touchmove 事件处理函数,会默认为是 passive: true。浏览器忽略 preventDefault() 就可以第一时间滚动了。
    但这样的后果是,如果在以上这 3 个元素的 touchstart 和 touchmove 事件处理函数中调用 e.preventDefault() ,会被浏览器忽略掉,并不会阻止默认行为。

    解决办法一:css touch-action: none;
    解决办法二:注册处理函数时,用如下方式,明确声明为不是被动的 window.addEventListener('touchmove', func, { passive: false })

  • 相关阅读:
    深圳中学校长推荐上北大 7尖子现场决出3名额
    到处Excel的数据格式设置
    转:乔布斯留给我们的十条经验
    GridView中DataFormatString属性的取值
    开发Windows服务的示例
    关于页面验证问题
    window.showModalDialog()弹出窗口获取返回值
    sql server 2000 MMC不能打开的处理方法
    基于微软平台IIS/ASP.NET开发的大型网站有哪些?
    开源相关社区/项目一览(备查,欢迎补充)
  • 原文地址:https://www.cnblogs.com/xfcao/p/14266198.html
Copyright © 2011-2022 走看看