程序:Eclipse(Phonegap)
电话:HTC Desire(2.2.2)
我已经玩iscroll插件一段时间了,但似乎我无法让它发挥作用。当我在android模拟器和手机中测试它时,它会一直滚动回顶部。LogCat还提供了以下行:
Javascript:
<script type="text/javascript">
var theScroll;
function scroll() {
theScroll = new iScroll('scroll-content', { snap:true, momentum:false, hScrollbar:false, vScrollbar:false});
setTimeout(function () { theScroll.refresh() }, 0);
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', scroll, false);
</script>
HTML:
<div id="wrapper">
<div id="main-content">
<div id="pages">
<div id="map" class="current">
</div>
<div id="camera">
<button class="camera-control" onclick="capturePhoto();">Capture Photo</button>
<div style="text-align:center; margin:20px 0 0 0;">
<img id="cameraPic" src="" style="width:50%; height: 50%;"/>
</div>
</div>
<div id="buzz">
<div id="scroll-content">
<ul id="your-tweets"></ul>
</div>
</div>
<div id="info">
<p>Informatie Evident</p>
</div>
</div>
</div>
</div>
我正在用JSON调用的tweet填充列表。希望有人能帮忙!
iScroll的完整语法为:iScroll(element_id,object options)。选项在这里。在选项中,我们有bounceLock(如果设置为true,则如果内容小于可见区域,滚动条将停止跳动。默认值为false)。
希望这就是您搜索的
为了防止它滚动到顶部,您需要在第一次"显示"元素后创建滚动对象。要向该元素动态添加数据并使用滚动条保持正确的滚动,您可以在每次向列表添加数据后使用以下脚本:
var myScroll = null; //set this initially
// Check if scroll has been created, if so, destroy and recreate
if (myScroll != null){
myScroll.destroy();
}
myScroll = new iScroll('call-list', { desktopCompatibility: true, vScroll: true, hScroll: false, hScrollbar: false, lockDirection: true });