简体   繁体   English

如何停止页面滚动...仍然允许滚动?

[英]How to stop page scrolling while…still allowing scrolling?

I'm making a mobile app with PhoneGap. 我正在使用PhoneGap制作移动应用程序。 I've got this-- 我有这个 -

function preventBehavior(e)
{
e.preventDefault();
};
document.addEventListener("touchmove",preventBehavior, false);

You know how you can drag a page a tiny ways off of the smartphone screen by dragging it, and then it pops right back when you release it? 您知道如何通过拖动页面将页面拖离智能手机屏幕一小段距离,然后当您释放它时它会立即向后弹出? And all you see behind it is black? 而你背后看到的只是黑色? That's what this code is meant to prevent. 这就是这段代码的意图。 And it does. 确实如此。

But it's also preventing all standard scrolling, such as scrolling through a list. 但它也阻止了所有标准滚动,例如滚动列表。 Does anyone know a solution? 有谁知道解决方案?

An easy solution for Cordova 1.7+ Locate Cordova.plist in your Xcode project. Cordova 1.7+的简单解决方案在您的Xcode项目中找到Cordova.plist。 At the top it will say “UIWebViewBounce“. 在顶部它会说“UIWebViewBounce”。 Set this to NO. 将此设置为NO。

you have two options: 你有两个选择:

  1. iScroll - Super effective in giving this effect. iScroll - 提供此效果的超级效果。 Granted it does have it's limitations. 虽然它确实有它的局限性。

  2. -webkit-overflow-scrolling:touch; -webkit溢出滚动:触摸; a new css method introduced in ios 5 it works well but again has it's limitations within phonegap. 在ios 5中引入了一种新的css方法它运行良好但又在phonegap中有其局限性。

Personally I use iScroll for phonegap apps, it works great if you don't have a super large list of items you are scrolling. 我个人使用iScroll作为phonegap应用程序,如果你没有滚动的超大项目列表,它会很有用。 If you're looking for a more native way I would suggest the overflow-scrolling method, this has proven to cause some strange effects in the webview. 如果你正在寻找一种更原生的方式,我会建议使用溢出滚动方法,这已经证明在webview中会产生一些奇怪的效果。 Phonegap uses webview vs mobile safari so your support differs a bit. Phonegap使用webview vs mobile safari,所以你的支持有点不同。

iScroll - http://cubiq.org/iscroll-4 webkit-scrolling - http://johanbrook.com/browsers/native-momentum-scrolling-ios-5/ iScroll - http://cubiq.org/iscroll-4 webkit-scrolling - http://johanbrook.com/browsers/native-momentum-scrolling-ios-5/

You should add this in your head tag: (No need of your listener code now) 你应该在你的head标签中添加它:(现在不需要你的监听器代码)

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

This basically disables the scaling (zoom in/out) and that drag effect which you do not want. 这基本上禁用了缩放(放大/缩小)和你不想要的拖动效果。 So the page will not be scrolled but still touchmove event can be tracked. 因此页面不会滚动但仍然可以跟踪事件触摸事件。

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

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