Javascript document.addEventListener("touchmove", preventBehavior, false); - 阻止我使用溢出:滚动;- 解决?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10814838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 03:03:26  来源:igfitidea点击:

document.addEventListener("touchmove", preventBehavior, false); - prevents me using from using overflow: scroll; - work around?

javascriptioscordovaoverflowtouchmove

提问by sam

Im using phonegap to build an ios app, so that you cant move the window phonegap uses document.addEventListener("touchmove", preventBehavior, false);

我使用 phonegap 来构建一个 ios 应用程序,这样你就不能移动 phonegap 使用的窗口 document.addEventListener("touchmove", preventBehavior, false);

which is fine... but it also prevent me from using the css overflow:scrollon a section of text.

这很好......但它也阻止我overflow:scroll在一段文本上使用 css 。

Is there a work arround that i can get both of these to still work ? is there a way i could load in the section of css after the js so that it overrides it ? or can i just apply the document.addEventListener("touchmove", preventBehavior, false);to the body but not its content ?

有没有什么工作可以让这两个都继续工作?有没有办法可以在 js 之后加载 css 部分,以便它覆盖它?或者我可以只将 应用于document.addEventListener("touchmove", preventBehavior, false);身体而不是它的内容吗?

回答by sam

Found a phonegap / cordova only work around that dosnt require you to use document.addEventListener("touchmove", preventBehavior, false);in the first place - go into your xcode project.. porject file > supporting files > cordova.plist then at the top change 'UIWebViewBounce' to NO.

发现一个 phonegap/cordova 只能解决那个不需要你首先使用document.addEventListener("touchmove", preventBehavior, false);的问题 - 进入你的 xcode 项目.. porject 文件 > 支持文件 > cordova.plist 然后在顶部将“UIWebViewBounce”更改为“否”。

from here

这里

回答by Bharath

To capture all the scrolling pixels you can write

要捕获您可以编写的所有滚动像素

document.addEventListener("touchStart",<method>,true/false)
document.addEventListener("touchMove",<method>,true/false)
document.addEventListener("touchEnd",<method>,true/false) 

Have you added touchEventListener in body load function ? If you write event.preventDefault(); It will kill the event behavior that is the reason why your overflow:scroll property is not working.

您是否在正文加载功能中添加了 touchEventListener ?如果你写 event.preventDefault(); 它将终止事件行为,这就是您的 overflow:scroll 属性不起作用的原因。

回答by Kevin

I think you can detect the target element when "touchmove":

我认为您可以在“touchmove”时检测到目标元素:

document.addEventListener("touchmove", function(event) {

    if (event.target.tagName != "TEXTAREA") { // Element that you don't want to be prevented default event.

          event.preventDefault();
    }
});

回答by Martin

In the last version cordova.plist changed by config.xml, then set

在上个版本中将cordova.plist 改为config.xml,然后设置

"UIWebViewBounce" value="false"

“UIWebViewBounce”值=“假”