2

好的,所以我发现使用 Jquery Mobile 和 Phonegap 开发 android App 在 android 4+ 中运行良好,但在旧版本(例如 2.2.2)上,可滚动功能中断。所以我尝试使用 iScroll,但出现了相互矛盾的问题,最终我决定编写一个 Javascript 函数来处理它。它以前可以工作,但现在坏了。

所以这里是:

<!DOCTYPE HTML>
    <html>

<head>

<title>Cordova</title>

            <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
            <script type="text/javascript" charset="utf-8" src="js/jquery-1.8.1.min.js"></script>
            <script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.2.0-beta.1.min.js"></script>


            <style>
            .scrollstyle{
            height: 320px;
            }
            </style>


            <script type="text/javascript">

             document.addEventListener("deviceready", checkVersion, false);

                function checkVersion() {

                    var droidversion = device.version;

                    myversion = droidversion.substr(0,1);

                    alert(myversion);

                    if ( parseInt(myversion) < 3 ) {
                        alert("do the scroll");
                        setTimeout(function () {
                            var startY = 0;
                            //var startX = 0;
                            var b = document.body;
                            b.addEventListener('touchstart', function (event) {
                                startY = event.targetTouches[0].screenY;
                                //startX = event.targetTouches[0].screenX;
                            });

                            b.addEventListener('touchmove', function (event) {
                                event.preventDefault();
                                var posy = event.targetTouches[0].screenY;
                                var h = parent.document.getElementById("scrolldroid");
                                var sty = h.scrollTop;

                                //var posx = event.targetTouches[0].screenX;
                                //var stx = h.scrollLeft;
                                h.scrollTop = sty - (posy - startY);
                                //h.scrollLeft = stx - (posx - startX);
                                startY = posy;
                                //startX = posx;
                            });
                        }, 1000);

                    } else {
                        alert("havent done it!");
                        return false;
                    }
                }


            </script>

            <link rel="stylesheet" href="css/jquery.mobile-1.2.0-beta.1.min.css" type="text/css" />

    </head>
    <body>
            <div data-role="dialog" id="main" data-theme="a">

                <div data-role="header" class="header">

                    <h1>Styles</h1>

                </div><!-- /header -->

                    <div data-role="content" data-them="a">

                        <div id="scrolldroid" class="scrollstyle">


                                <ul data-role="listview">     
                                    <li>OK, that works, but why is the scrollbar</li>
                                    <li> scrolled down to the bottom of the dialog </li>
                                    <li>fsgsgestcontent, and not at the </li>
                                    <li>Line4</li>
                                    <li>Line5</li>
                                    <li>Line6</li>
                                    <li>Line7</li>
                                    <li>Line8</li>
                                    <li>Line9</li>
                                    <li>Line10</li>
                                    <li>Line11</li>
                                    <li>Line12</li>
                                    <li>Line13</li>
                                    <li>Line14</li>
                                    <li>Line15</li>
                                    <li>Line16</li>
                                    <li>Line17</li>
                                    <li>Line18</li>
                                    <li>Line19</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                    <li>fsgsgesthsdgfeagsdgsdgwe4ghesgaegeg</li>
                                </ul>

                        </div>   

                    </div><!-- /content -->

                <div data-role="footer" class="footermodal">
                    <h1>footer</h1>

                </div><!-- /footer -->

            </div>
        </body>
    </html>

我仍然是一名初级开发人员,所以我的代码并不完美,抱歉。但它应该可以工作,在 Android 3+ 中它不执行该功能,因为滚动已经工作。在 Android 2.9.9 或更低版本中可以。它应该使 div 可滚动,但它没有,它曾经是但后来我以某种方式打破了它,我不知道如何。如果有人知道或可以看到它坏了,我会永远爱你告诉我。谢谢。

编辑我还在 Eclipse LogCat 中不断收到一个黄色错误,指出:“我们正在等待 WebCore 对着陆的响应,所以错过了一次拖动”

4

1 回答 1

0

尝试替换:

<div data-role="dialog" id="main" data-theme="a"> 

经过

<div data-role="page" id="main" data-theme="a">

并删除 id为 scrolldroid的 div

<div id="scrolldroid" class="scrollstyle"> </div>

并替换:

<div data-role="footer" class="footermodal">

经过

<div data-role="footer" data-position="fixed" data-tap-toggle="false">
于 2012-09-21T14:29:41.103 回答