pagebeforeshow中的jQuery Mobile changePage Flicker

时间:2013-04-17 22:07:45

标签: jquery-mobile

在我的几个jQuery Mobile页面中,我需要确保在允许页面显示之前设置某些变量。因此,我在pagebeforeshow事件中检查这些变量,如果它们不存在或不正确,我会调用$.mobile.changePage(...)事件中的pagebeforeshow,然后立即返回。

在jQuery Mobile 1.2.1中,这似乎完美无缺。但是,现在我正在使用jQuery Mobile 1.3.1,我注意到一个奇怪的渲染问题。现在当我在pagebeforeshow事件中调用changePage时,它会导致jQuery Mobile转换到我请求的页面,然后返回到原始页面,触发pageshow事件,然后最终转换回页面我将changePage改为。

虽然不是主要问题,但这会带来不便并导致不必要的过渡。有没有其他人遇到过这个问题,如果有的话,你能否防止不必要的过渡和事件发生?谢谢!

示例代码:

$('#ConditionalPage').on('pagebeforeshow', function () {
    if (!someScopedVariable) {
        $.mobile.changePage('#RegularPage');
        return;
    }
}

$('#ConditionalPage').on('pageshow', function () {
    ... \\ Code that gets fired even though pagebeforeshow called changePage.
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。当我将页面从一个页面更改为另一个页面时,它很好。但当我换回时:

$.mobile.changePage("#frontPage");

页面在两页之间移动了几次。

通过移动我定义的一些功能来解决问题:

$(document).on('pagebeforeshow', '[data-role=page]', function () {...})

成:

$(document).on('pageinit', '[data-role=page]', function () {...})