首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何防止手机间隙中运行的app出现垂直滚动?

如何防止手机间隙中运行的app出现垂直滚动?
EN

Stack Overflow用户
提问于 2011-06-01 04:13:10
回答 10查看 64.3K关注 0票数 60

我正在尝试phone gap,我希望当用户在屏幕上拖动手指时,我的应用程序不会上下滚动。这是我的代码。有人能告诉我为什么它还允许滚动吗?

代码语言:javascript
复制
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta name = "viewport" content = "user-scalable=no,width=device-width" />
    <!--<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />-->

    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

    <!-- iPad/iPhone specific css below, add after your main css >
    <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" />        
    <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />       
    -->
    <!-- If you application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here -->
    <script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.1.min.js"></script>
    <script type="text/javascript" charset="utf-8">


    // If you want to prevent dragging, uncomment this section
    /*
    function preventBehavior(e) 
    { 
      e.preventDefault(); 
    };
    document.addEventListener("touchmove", preventBehavior, false);
    */

    /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
    see http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
    for more details -jm */
    /*
    function handleOpenURL(url)
    {
        // TODO: do something with the url passed in.
    }
    */

    function onBodyLoad()
    {       
        document.addEventListener("deviceready",onDeviceReady,false);
    }

    /* When this function is called, PhoneGap has been initialized and is ready to roll */
    /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
    see http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
    for more details -jm */
    function onDeviceReady()
    {
        // do your thing!
        navigator.notification.alert("PhoneGap is working")
    }
    touchMove = function(event) {
        // Prevent scrolling on this element
        event.preventDefault();
    }

</script>
<style>
#container {
width:100%;
height:100%;
}
</style>

</head>

    <body onload="onBodyLoad()">
        <div id="container" ontouchmove="touchMove(event);">
        </div>
    </body>
</html>
EN

回答 10

Stack Overflow用户

发布于 2011-06-09 06:57:14

加载页面时运行此代码以禁用拖动:

代码语言:javascript
复制
document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);

下面是一个使用jQuery的示例:

代码语言:javascript
复制
$(document).ready(function() {
    document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
});
票数 35
EN

Stack Overflow用户

发布于 2015-07-10 17:42:13

在配置文件中使用

代码语言:javascript
复制
<preference name="webviewbounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
票数 20
EN

Stack Overflow用户

发布于 2013-08-17 04:45:46

将以下条目添加到config.xml文件:

代码语言:javascript
复制
<preference name="DisallowOverscroll" value="true" />
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6193016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档