【问题标题】:iScroll Not scrolling content, just bounces back to topiScroll 不滚动内容,只是弹回顶部
【发布时间】:2012-06-15 22:07:53
【问题描述】:

我已经阅读了很多关于此的论坛,但没有一个能解决我的问题。我确定它是我缺少的一些小东西

这里是iscroll初始化:

// make PI scroll
piScroll2 = new iScroll('pi_scroll2');

这是我的 CSS:

.pi_panel.large .content{
position: absolute;
width: 963px;
height: 616px;
top: 65px;
left:30px;
background:none;
/*background:url(../images/ISI_body.png) repeat-y;*/
overflow:scroll;
    -webkit-border-radius: 0px;

}

#FullPiWrapper
{
   position:relative; 
   z-index: 1; 
   overflow:hidden; 
   top: 60px; 
   width:980px;
   height: 610px;
}

.pi_panel .pi_box{
padding: 0px;
margin: 20px 0px;

}

这是我的html:

<!-- BEGIN:   PI PANEL LARGE -->
    <div class="pi_panel large">
     <div class="topBarPiFull">
                <div class="title">Full Prescribing Information</div>
                <div class="close_button_fullpi">Close</div>
                <div class="annotated_pi_button">Annotated PI</div>
            </div>
<!--            <div class="popContent"></div>-->
          <div class="content" id="FullPiWrapper">

                <div id="pi_scroll2">


                    <div class="pi_box" >
                        <img src="_globals/images/PI/pi_1.png"/>
                        <img src="_globals/images/PI/pagebreak.png" />
                        <img src="_globals/images/PI/pi_2.png"/>
                        <img src="_globals/images/PI/pagebreak.png" />
                        <img src="_globals/images/PI/pi_3.png"/>
                        <img src="_globals/images/PI/pagebreak.png"/>
                        <img src="_globals/images/PI/pi_4.png"/>
                        <img src="_globals/images/PI/pagebreak.png"/>
                        <img src="_globals/images/PI/pi_5.png"/>
                        <img src="_globals/images/PI/pagebreak.png" />
                        <img src="_globals/images/PI/pi_6.png"/>
                        <img src="_globals/images/PI/pagebreak.png" />
                        <img src="_globals/images/PI/pi_7.png"/>
                        <img src="_globals/images/PI/pagebreak.png" />
                        <img src="_globals/images/PI/pi_8.png"/>
                        <img src="_globals/images/PI/pagebreak.png" />
                        <img src="_globals/images/PI/pi_9.png"/>
                        <img src="_globals/images/PI/pagebreak.png" />
                        <img src="_globals/images/PI/pi_10.png"/>
                    </div>
                 </div>

            </div>
     </div>
    <!-- END:   PI PANEL LARGE -->

【问题讨论】:

    标签: iscroll


    【解决方案1】:

    问题是,当页面首次加载时,您不能将任何父级的 div 类显示设置为“无”。所以我将 'pi_panel large' 设置为 display: 'block';

    【讨论】:

    • 我加 1。要添加到您的答案,iscroll 的容器元素必须在 iscroll 初始化之前可见。我刚刚在 ipad webapp 上使用 iscroll 进行了战斗,所有视图都是动态显示的。
    • ** 另请参阅此处有关 iscroll 5 问题的答案:stackoverflow.com/questions/25962095/…
    【解决方案2】:

    确保容器的高度超过包装器的高度,即不要创建height:100%。例如,如果 wrapper 包含一个容器,并且容器中有 10 个 div:

    如果每个 div 为 100px,则包装器可能为 150px。那么 Container 必须是 1000px (不是 100% !)

    【讨论】:

      【解决方案3】:

      给你的包装一个高度,它对我有用。

      .wrapper1 {
          position:absolute; z-index:1;
          top:250px; bottom:0px; left:3%;
          margin-left:25px;
          width:100%;
          background:none;
          overflow:auto;
          height:100px;
      }
      

      【讨论】:

        【解决方案4】:

        要解决“div display none”问题,请在将数据加载到网格、div 等后执行以下操作:

                    myScroll.refresh();
                    myScroll.scrollTo(0, 0, 1000);
        

        myScroll 的加载位置:

        var myScroll = new iScroll('friendsWrapperDrug', { desktopCompatibility: true, vScroll: true, hScroll: false, hScrollbar: false, lockDirection: true });

        【讨论】:

          【解决方案5】:
          myScroll.refresh();
          myScroll.scrollTo(0, 0, 0);
          

          【讨论】:

            【解决方案6】:

            当您的wrapper 有一个container div 时会出现此问题。解决此问题的方法是将container 的高度设置为99%

            以下是最终为我解决此问题的 CSS:

            #productsScreen{ /* my container */
                height: 99%;
                z-index: 1;
                top: 0px;
                left: 0;
                overflow: auto;
            }
            #productListWrapper{
                background:transparent;
                position:absolute; 
                z-index:1;
                top: 88px;
                bottom:49px; 
                left:0;
                width:100%;
                overflow:auto;
            }
            #productsListScroller {
                position:absolute; z-index:1;
                -webkit-tap-highlight-color:rgba(0,0,0,0);
                width:100%;
                padding:0;
                -webkit-box-sizing: border-box;
                -moz-box-sizing: border-box;
                -o-box-sizing: border-box;
                box-sizing: border-box;
            }
            

            希望有帮助!

            【讨论】:

              【解决方案7】:

              另一个对我有用的解决方案是使用 setTimeout 包装 iScroll init 函数。这将为浏览器在应用 iScroll 之前渲染元素提供一些时间。

              【讨论】:

              • 这是个糟糕的主意。在 DOM 就绪或显示滚动条时执行此操作(如果您正在动态更改可见性)
              猜你喜欢
              • 2023-04-07
              • 1970-01-01
              • 1970-01-01
              • 2021-08-20
              • 1970-01-01
              • 1970-01-01
              • 2018-11-15
              • 2011-12-17
              • 2019-03-15
              相关资源
              最近更新 更多