-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
禁止微信页面及iOS Safari拖动露底效果 (橡皮筋) #3
Comments
如何判断滑动事件的触发 target 祖先元素是否有可滑动元素,无则直接阻止冒泡。
|
|
判断滑动方向
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
花式提升移动端交互体验
解决思路很明显:当容器可以滑动时,若已经在顶部,禁止下滑;若在底部,禁止上滑;容器无法滚动时,禁止上下滑。
基本实现方式是通过 document 上监听 touchstart 和 touchmove 事件,判断滑动方向;判断滑动事件的触发 target 祖先元素是否有可滑动元素,无则直接阻止冒泡。
若有这种祖先元素,判断其状态:offsetHeight >= scrollHeight 高度不够发生滚动,阻止冒泡;若可滚动 scrollTop === 0 即在顶部,阻止下滑的冒泡;若 scrollTop + offsetHeight >= scrollHeight 已经滑到底,阻止上滑的冒泡。
还需注意的是,要先判断滑动时 x 轴位移是否大于 y 轴 ,即是否是水平滑动,防止“误伤”一些水平滚动的元素。
The text was updated successfully, but these errors were encountered: