简体   繁体   English

iOS Webapp:禁用除textarea之外的页面滚动

[英]iOS Webapp: Disable scroll on page except for textarea

I'm making a webapp for iOS. 我正在为iOS开发一个webapp。 I want it to be not-scrollable, with the exception of a textarea (that needs to be scroll-able). 我希望它是不可滚动的,但文本区域除外(该区域必须是可滚动的)。 I've tried looking around at similar problems such as this one disable enter key on page, but NOT in textarea without luck (that example looked the most promising, but I got "can't find variable node" error in Safari). 我曾尝试查看类似的问题,例如在页面上禁用输入键,但是在没有运气的textarea中不是这样(该示例看起来是最有前途的,但是在Safari中出现“找不到变量节点”错误)。

Can anyone help me with this? 谁能帮我这个? Thanks 谢谢

Didn't solve my problem but helpful - marked best answer 无法解决我的问题,但有帮助-标记为最佳答案

You could see if the user is trying to scroll (usually one finger moving on the screen indicates a scroll), and using an onTouchMove event Listener, prevent default and propagation. 您可以看到用户是否尝试滚动(通常一个手指在屏幕上移动表示滚动),并使用onTouchMove事件侦听器防止默认行为和传播。

var element = document.getElementById("textarea");
element.addEventListener("touchmove",function(e){onTouchMove(e)},false);

function onTouchMove(e) {

    if(e.touches.length != 1) return;

    e.stopPropagation();
    e.preventDefault();

}

iDevices are kind of tricky when it comes to scrolling internal elements anyway; 无论如何,iDevice在滚动内部元素时都比较棘手。 usually people are trying to achieve scroll effects on inner elements :) 通常人们试图在内部元素上实现滚动效果:)

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

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