javascript-iscroll在phonegap中不起作用?如何在phonegap中使用iscroll

我已经在android phonegap中创建了应用程序.我使用iscoll在div中动态显示滚动条,因为我追加了列表并动态显示.

它显示带有附加列表的div,但不显示滚动条.

在logcat中,出现以下错误:

03月21日16:09:02.669:WARN / webview(2166):由于我们正在等待WebCore的触地响应而错过了一次拖动.

我的代码是

我已经使用cubiq.org/iscroll-4显示滚动条

滚动条的js是

<script type="text/javascript" charset="utf-8" src="iscroll.js"></script>

<script type="text/javascript">

显示滚动条的功能

var scroll1;
function loaded() {
    scroll1 = new iScroll('standard');


}

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
</script>

滚动条的CSS

<style type="text/css" media="all">

body {
    font-size:12px;
    -webkit-user-select:none;
    -webkit-text-size-adjust:none;
    font-family:helvetica;
    padding:20px;
}

#standard {
    position:relative; z-index:1;
    display:block; float:left;
    width:100px; height:150px;
    background:#aaa;
    overflow:auto;
    border:1px solid #aaa;
}

#standard {
    margin-right:20px;
}

.scroller {
    position:absolute; z-index:1;

    -webkit-tap-highlight-color:rgba(0,0,0,0);
    width:100%;
    padding:0;
}
</style>

我已经用div(id =“ list”)追加了列表,并用div(id =“ button”)追加了按钮

<div id="standard">
    <div class="scroller">
         <div id="button"></div>
       <div id="list">

       </div>

    </div>
</div>

如何显示带有动态div的scroollbar?请指导我.提前致谢

解决方法:

我假设您正在谈论水平滚动,此时属性hScroll默认为true.如果是垂直的,则在创建iScroll元素时也需要将vScroll设置为true.

如果您具有动态生成的列表,则需要使用scroll1.refresh()来注意生成的内容.

另外,因为iScroll将其切换为“溢出:隐藏”,所以没有必要为#standard设置“ overflow:auto”.

但是,正如文档中所述,使iScroll正常工作的最佳方法是采用如下结构(我假设您已经拥有):

<div id='ScrollWrapper'>
<ul>
  <li>content</li>
</ul>
</div>
上一篇:使用Phonegap在Android上的Media Player中打开RTSP链接


下一篇:如何使用senchatouch 2在android中实现phonegap应用程序