简体   繁体   English

当在特定 Div 上启动滑动时,如何在移动设备上禁用页面滚动?

[英]How to disable scrolling of the page on mobile when the swipe is initiated on a specific Div?

I have a fixed menu at the bottom of the screen on mobile devices.我在移动设备的屏幕底部有一个固定菜单。 When you swipe up in the trigger area, it opens the menu and vice versa (closes it when you swipe down on the menu)当您在触发区域向上滑动时,它会打开菜单,反之亦然(当您在菜单上向下滑动时会关闭它)

My issue is that when I swipe up, it scrolls the page down and when I swipe down it scrolls the entire page up.我的问题是,当我向上滑动时,它会向下滚动页面,而当我向下滑动时,它会向上滚动整个页面。

How can I disable page scrolling when the swipe is initiated in a certain area?当在某个区域启动滑动时,如何禁用页面滚动?

Add class in body tag when you swipe up from your bottom menu.当您从底部菜单向上滑动时,在 body 标签中添加类。 In that new class put overflow hidden CSS.在那个新类中放置溢出隐藏的 CSS。 I suggest it looks good if you add click effect instead of swipe up.我建议如果你添加点击效果而不是向上滑动它看起来不错。 Or here this is one similar question.或者这是一个类似的问题。

 $('#menu li a').on('click', function(){ $('body').removeClass('overflow-hidden'); $(this).parents('body').addClass('overflow-hidden'); });
 .overflow-hidden{ overflow: hidden; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM