将iScroll与phonegap一起使用

时间:2012-07-23 18:17:28

标签: cordova iscroll

我希望我的应用程序可以垂直滚动,并希望使用iscroll来执行它。我不确定如何使用它。似乎应用程序仍然无法垂直滚动。 代码:

      <head>
        <script type="text/javascript" src="iscroll.js"></script>
        <script type="text/javascript">
                var myScroll;
                function loaded() {
                    setTimeout(function () {
                               myScroll = new iScroll('container');
                               }, 100);
                }
                window.addEventListener('load', loaded, false);
        </script>
       </head>
       <body>
              <div class="container">
                <div class = "topcontainer">
                    <div class = "buttons img1"> </div>
                    <div class = "buttonstext">
                        Gallery
                    </div>
                </div>
                <div class = "middlecontainer">
                    <div class = "buttons img2">
                        <a href="gallery.html">Biography</a>      
                    </div>
                </div>
                <div class = "middlecontainer">
                    <div class = "buttons img3">
                        Pictures
                    </div>
              </div>
        </body>

在我出错的地方需要一些指导。我还需要做别的吗?

1 个答案:

答案 0 :(得分:1)

iScroll在初始化时将元素的id作为参数 - 而不是类。因此,例如,将div.container更改为div#container

  <head>
    <script type="text/javascript" src="iscroll.js"></script>
    <script type="text/javascript">
            var myScroll;
            function loaded() {
                setTimeout(function () {
                           myScroll = new iScroll('container');
                           }, 100);
            }
            window.addEventListener('load', loaded, false);
    </script>
   </head>
   <body>
          <div id="container">
            <div class = "topcontainer">
                <div class = "buttons img1"> </div>
                <div class = "buttonstext">
                    Gallery
                </div>
            </div>
            <div class = "middlecontainer">
                <div class = "buttons img2">
                    <a href="gallery.html">Biography</a>      
                </div>
            </div>
            <div class = "middlecontainer">
                <div class = "buttons img3">
                    Pictures
                </div>
            </div>
          </div>
    </body>

有关详细信息,请参阅iScroll 4的documentationiScroll 3。我无法找到它明确指出需要在iScroll 4文档上传递ID的位置,但所有示例代码都支持此功能。此外,iScroll 3文档中明确说明了此

另外:您在示例代码中缺少结束</div>。这已在我的回复中修复。