简体   繁体   English

防止页面滚动,但允许具有溢出滚动的元素滚动JQM

[英]Prevent page scroll but allow element with overflow scroll to scroll JQM

I have a page in jquery mobile, I want to prevent the page from scrolling but allow the user to scroll an element on the page that has overflow set to scroll. 我在jquery mobile中有一个页面,我想防止页面滚动,但允许用户滚动页面上已设置了滚动溢出的元素。 Should be noted that the reason I need this is because the page length will vary slightly, beyond 100% on some different devices. 应该指出的是,我需要这样做的原因是因为页面长度会略有不同,在某些不同的设备上会超过100%。

<div data-role="page" id="noscroll>
    <div data-role="content">
         <div class="scrollable">
         </div>
    </div>
</div>

I've tried something like this but obviously this prevents the scrollable element from responding to the touchmove event. 我已经尝试过类似的操作,但是显然这阻止了scrollable元素响应touchmove事件。

$('#noscroll').on('touchmove', function(){
      e.preventDefault();
      });

Try this type of approach : 试试这种方法:

$('*:not(.scrollable)').on('scroll touchmove', function(e){
    e.preventDefault();
});

not tested but should be a start to find the correct way to do what you want. 尚未测试,但应该开始寻找正确的方法来做自己想要的事情。

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

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