使用iscroll和jquery mobile

时间:2011-10-07 16:45:30

标签: jquery jquery-mobile iscroll4

我正在努力让我的头发试图让iscroll 4与jQuery Mobile合作。

一切正常,我禁用了JQM ajax默认导航,但我想保留它。

我的问题是我无法解决如何成功调用/绑定iscroll以使其适用于需要它们的页面。我试过pageinit()和pagecreate()无济于事。

任何指针都非常赞赏。

一个。

1 个答案:

答案 0 :(得分:8)

我在pageshoworientationchange事件上初始化/刷新iScroll实例。我在data-role="content" div上设置了一个我想要滚动的类(在这个例子中我使用了.content类)。

var myScroll = [];
$(document).delegate('[data-role="page"]', 'pageshow', function () {
    if ($.mobile.activePage.find('.content').length > 0) {
        if (this.id in myScroll) {
            myScroll[this.id].refresh();
        } else {
            myScroll[this.id] = new iScroll($.mobile.activePage.find('.content')[0].id, {
                hScroll        : false,
                vScroll        : true,
                hScrollbar     : false,
                vScrollbar     : true,
                fixedScrollbar : true,
                fadeScrollbar  : false,
                hideScrollbar  : false,
                bounce         : true,
                momentum       : true,
                lockDirection  : true
            });
        }
    }
});

$(window).bind('orientationchange', function () {
    if ($.mobile.activePage[0].id in myScroll) {
        myScroll[$.mobile.activePage[0].id].refresh();
    }
});
相关问题