问题描述
在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,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>
解决方法
这不是Safari的错误,我可以使用Firefox和Chrome在OnePlus 6上复制“问题”。滚动过程中的第一次触摸会使其停止,这似乎与手机的操作系统有关。