jQTouch中的iscroll橡皮筋效果
我是一名新开发人员,正在尝试创建一个 jQTouch 应用程序来在多个页面中显示一些可滚动内容。我决定使用 iscroll,它只在主页上运行良好。我读过,我需要在每页后刷新 iscroll,但我完全不知道如何做到这一点。这是我的脚本:
<script type="text/javascript">
var myScroll, myScroll2;
function loaded() {
setTimeout(function () {
myScroll = new iScroll('wrapper1');
}, 100);
setTimeout(function () {
myScroll2 = new iScroll('wrapper2');
}, 100);
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
</script>
在我的 html 中,我有一个 div id="wrapper1"
,它工作正常,直到我导航到 div id="wrapper2"
所在的第二页橡皮筋效应。
I am a new developer and am trying to create a jQTouch application to display some scrollable content throughout multiple pages. I've decided to use iscroll and it only works fine on the home page. I've read that I need to refresh iscroll after each page but I am completely lost on how to do this. Here is my script:
<script type="text/javascript">
var myScroll, myScroll2;
function loaded() {
setTimeout(function () {
myScroll = new iScroll('wrapper1');
}, 100);
setTimeout(function () {
myScroll2 = new iScroll('wrapper2');
}, 100);
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', loaded, false);
</script>
In my html I have a div id="wrapper1"
which works fine until I navigate to the second page where the div id="wrapper2"
has the rubber band effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您还没有弄清楚这一点(尽管我确信您已经弄清楚),您想要:
或
In case you haven't figured this out yet (although I'm sure you have), you want:
or
好的,终于开始工作了。为了让 jQTOuch 和 iScroll 能够很好地配合,每次 JQTouch 使页面上的滚动区域消失时,都需要重置它们。换句话说,一旦隐藏 div,iScroll 就不知道下次它可见时要滚动什么。因此,你会得到臭名昭著的橡皮筋效应。要解决此问题,只需添加一个事件侦听器,在调用 div 后立即重置滚动区域。确保给它 100 到 300 毫秒的延迟。下面的代码假设您的变量名为
myScroll
:顺便说一下,以下是如何使用 iScroll 建立多个滚动条:
Ok finally got this working. To get jQTOuch and iScroll to play nice with each other, the scrolling areas on the page need to be reset each time JQTouch makes them disappear. In other words, once you hide the div, iScroll doesn't know what to scroll the next time it's made visible. So as a result, you get the infamous rubberband effect. To solve this, just add an event listener that resets the scrolling area right after the div is called. Make sure you give it 100 to 300ms delay. This code below assumes your variable is called
myScroll
:And on a side note, here's how to establish multiple scrollers using iScroll: