在jQuery Mobile上使用iscroll [英] using iscroll with jquery mobile

查看:106
本文介绍了在jQuery Mobile上使用iscroll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在努力让iscroll 4与jQuery Mobile配合使用.

Im currently pulling my hair out trying to get iscroll 4 working with jQuery Mobile.

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

It all works fine it i disable JQM ajax default navigation but I would like to retain this.

我的问题是我无法弄清楚如何成功调用/绑定iscroll,因此它可以与需要它们的页面一起使用.我尝试了pageinit()和pagecreate()无济于事.

My issue is I cant work out how to successfully call/bind iscroll so it works with the pages that need them. I have tried pageinit() and pagecreate() to no avail.

非常感谢任何指针.

A.

推荐答案

我在pageshoworientationchange事件上初始化/刷新iScroll实例.我在data-role="content" div上设置了一个我想使其可滚动的类(在这种情况下,我使用了.content类).

I initialize/refresh the iScroll instances on the pageshow and orientationchange events. I set a class on data-role="content" divs that I want to be scrollable (in this instance I used the .content class).

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();
    }
});

这篇关于在jQuery Mobile上使用iscroll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆