0

我希望我的应用程序可以垂直滚动并想使用 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>

需要一些指导,我哪里出错了。我需要做点别的吗?

4

1 回答 1

1

iScrollid在初始化时将元素作为参数 - 而不是类。因此,例如,将 更改div.containerdiv#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 或iScroll 3的文档。我找不到它明确指出需要在 iScroll 4 文档中传递 ID 的位置,但所有示例代码都支持这一点。此外,这在 iScroll 3 文档中明确说明。

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

于 2012-07-23T18:28:46.530 回答