【问题标题】:Touch events are not handled on iPhone Safari when page scrolled页面滚动时,iPhone Safari 上不处理触摸事件
【发布时间】:2020-08-19 12:37:19
【问题描述】:

在 iPhone 上的 Safari 上,如果您快速滚动页面,则在滚动停止之前不会处理 白框 事件。

(要查看此错误,您需要通过滑动来滚动页面并尝试在页面仍在滚动时触摸白色框。要查看预期行为,请尝试在不滚动页面的情况下触摸它。)

const fix = document.querySelector('.fix')
const text = document.querySelector('.handle')

fix.addEventListener('touchstart', handle)
fix.addEventListener('touchend', handle)
fix.addEventListener('mousedown', handle)
fix.addEventListener('touchmove', handle)

function handle(e){
  text.innerText  = e.type
  console.log(e)
}
.scroll{
  width: 100%;
  height: 2000vh;
  background: rgb(226,252,193);
background: linear-gradient(0deg, rgba(226,252,193,1) 0%, rgba(182,251,176,1) 3%, rgba(204,128,151,1) 49%, rgba(134,133,189,1) 75%, rgba(71,153,222,1) 98%, rgba(0,204,247,1) 100%);
}
*{
  padding: 0;
  margin: 0;
}
.fix{
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  bottom: 0;
  left: 0;
  right: 0;
  height: 150px;
  background-color: #fff;
}
.handle{
  font-size: 20px;
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
     -khtml-user-select: none; /* Konqueror HTML */
       -moz-user-select: none; /* Old versions of Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; 
}
<section class="scroll"></section>
<div class="fix">
  <p class="handle"></p>
</div>

Demo on CodePen

【问题讨论】:

  • 这在其他设备上工作正常吗?
  • 我在 android 上测试 - 它工作正常
  • 但在 IOS 中不工作

标签: javascript touch mobile-safari touch-event


【解决方案1】:

这不是 Safari 错误,我可以使用 Firefox 和 Chrome 在我的 OnePlus 6 上复制“问题”。滚动进行时的第一次触摸会停止滚动,这似乎与手机操作系统有关。

【讨论】:

  • 这是 Safari 错误。 iPhone 上的所有浏览器都有 safari 引擎
猜你喜欢
  • 2013-08-07
  • 2011-02-21
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-24
相关资源
最近更新 更多