Как предотвратить вертикальную прокрутку приложения, работающего в телефонном промежутке? - PullRequest
55 голосов
/ 01 июня 2011

Я испытываю разрыв телефона и хочу, чтобы мое приложение не прокручивало вверх и вниз, когда пользователь проводит пальцем по экрану. Это мой код Может кто-нибудь сказать мне, почему он все еще позволяет прокручивать?

   <!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>

Ответы [ 14 ]

1 голос
/ 01 мая 2013

теперь вам просто нужно поместить <preference name="DisallowOverscroll" value="false" /> в <preference name="DisallowOverscroll" value="true" /> в вашем файле config.xml.

0 голосов
/ 26 августа 2014

В config.xml вашего проекта в настройках iOS установите для DisallowOverscroll значение true.

0 голосов
/ 20 февраля 2013

Если в вашем файле .plist есть UIWebViewBounce to NO.

Тогда с помощью простого css содержимое не будет прокручиваться. Попробуйте добавить этот стиль переполнение: скрыто в ваш div, где вы хотите отключить прокрутку.

0 голосов
/ 31 мая 2012

Сначала вам нужно добавить прослушиватель событий в методе разгрузки тела.

просто поместите эту строку в метод сенсорного перемещения.

это не будет прокручиваться document.addEventListener ( "touchstart / TouchMove / touchend"). Любой из этих 3.

function touchMove (event e) {
    e.preventDefault;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...