Phonegap / jQuery Mobile幻灯片转换在第一次调用时无法正常工作。

10

我遇到了一个奇怪的视觉问题。我希望在应用程序更换页面时能有一个好看的过渡效果。 不幸的是,当我第一次切换到另一个页面时,当前页面并没有滑动出去,而是立即被新页面替换,然后才滑动出去。当第一个页面不再显示时,新页面才被显示出来。但第二次尝试就会像魔法般地正常运行!

这是在 iPhone 上使用 jQuery Mobile + PhoneGap 运行的。

我制作了一个视频来帮助澄清这个问题:http://www.youtube.com/watch?v=Ybvzh_wTnSE

    <body style="background-color: #000;">
        <div id="container" style="display:none;">
            <div id="side-menu" style="display:none;">
                <div id="header_top"></div>
                <a href="#dives" onclick="showdives();"><div id="header_dives" class="selected"></div></a>
                <div id="header_spacer1"></div>
                <a href="#explore" onclick="showexplore();"><div id="header_explore"></div></a>
                <div id="header_spacer2"></div>
                <a href="#search" onclick="showsearch();"><div id="header_search"></div></a>
                <div id="header_spacer3"></div>
                <a href="#settings" onclick="showsettings();"><div id="header_settings"></div></a>
                <div id="header_bottom"></div>
            </div>
            <div id="slide_mask">
                <!-- START of LOGIN page -->
                <div data-role="page" id="login">           
                    <div id="home_frame">
                        <div id="home_logo"></div>
                        <div id="home_fblogin" onclick="login()"></div>
                        <div class="home_login">
                            <p>Email: <input type="text"  name="user[email]" size="30"/></p>
                            <p>Password: <input type="password"  name="user[password]" size="30"/></p>
                            <button onclick="show_page_home();">LOGIN</button>
                        </div>
                    </div>
                </div>
                <!-- END of LOGIN page -->

                <!-- START of LOGIN page -->
                <div data-role="page" id="dives" class="right_pane">    
                        <p>My dives !</p>       
                </div><!-- /content -->
                <div data-role="page" id="explore" class="hidden right_pane">   
                        <p>My explore !</p>     
                </div><!-- /content -->
                <div data-role="page" id="search" class="hidden right_pane">    
                        <p>My search !</p>      
                </div><!-- /content -->
                <div data-role="page" id="settings" class="hidden right_pane">  
                        <p>My settings !</p>
                        <button onclick="logout_db();">logout</button>      
                </div><!-- /content -->
                <!-- END of LOGIN page -->
            </div>
        </div>
        <div id="log"></div>
        <div id="data"></div>
    </body>

以及相关的CSS:

    body {margin: 0; font: 18px Helvetica; text-align: center; background-color: #000; background: url(../img/bg_big.png) repeat;
        -webkit-user-select: none;  /* prevent copy paste for all elements */
        }
    #container { width:320px; height:460px; overflow: hidden;}

    input{ -webkit-user-select: text;  /* enable copy paste for elements with this class */}
    a {-webkit-user-select: none;  /* prevent copy paste for all elements */}
    span {-webkit-user-select: none;  /* prevent copy paste for all elements */}

    #side-menu {z-index: 1000 !important; position: fixed; height: 460px; width: 56.5px; background: url(../img/bg_big.png) no-repeat; display: inline-block;
    overflow: hidden; top: 0px; left: 0px; }
    #header_top {background: url(../img/header/header_top.png) no-repeat; background-size: 56.5px 48.96px; width: 56.5px; height: 48.96px; display: block;}
    #header_dives {background: url(../img/header/dives.png) no-repeat; background-size: 56.5px 51.75px; width: 56.5px; height: 51.75px; display: block;}
    #header_dives.selected{background: url(../img/header/dives_selected.png) no-repeat;}
    #header_spacer1{background: url(../img/header/header_space1.png) no-repeat; background-size: 56.5px 13.9px; width: 56.5px; height: 13.9px; display: block;}
    #header_explore{background: url(../img/header/explore.png) no-repeat; background-size: 56.5px 51.75px; width: 56.5px; height: 51.75px; display: block;}
    #header_explore.selected{background: url(../img/header/explore_selected.png) no-repeat;}
    #header_spacer2{background: url(../img/header/header_space2.png) no-repeat; background-size: 56.5px 15.33px; width: 56.5px; height: 15.33px; display: block;}
    #header_search{background: url(../img/header/search.png) no-repeat; background-size: 56.5px 51.75px; width: 56.5px; height: 51.75px; display: block;}
    #header_search.selected{background: url(../img/header/search_selected.png) no-repeat;}
    #header_spacer3{background: url(../img/header/header_space3.png) no-repeat; background-size: 56.5px 17.73px; width: 56.5px; height: 17.73px; display: block;}
    #header_settings{background: url(../img/header/settings.png) no-repeat; background-size: 56.5px 51.75px; width: 56.5px; height: 51.75px; display: block;}
    #header_settings.selected{background: url(../img/header/settings_selected.png) no-repeat;}
    #header_bottom{background: url(../img/header/header_bottom.png) no-repeat; background-size: 56.5px 160px; width: 56.5px; height: 160px; display: block;}

    .hidden {display: none;}
    .right_pane{width: 263.5px !important; background: url(../img/right_bg.png) no-repeat; background-size:263.5px 460px; width: 263.5px; height: 460px; left: 56.5px !important;}
    #slide_mask{ display: inline-block; overflow: hidden; padding-left: 56.5px;  width: 263.5px; height: 460px; top: 0;}

还有一点JS代码:

    ///////////////////////////////////
    //MENU MECHANICS
    ///////////////////////////////////

    function showdives(){
        $("#side-menu .selected").removeClass("selected");
        $("#header_dives").addClass("selected");
    }

    function showexplore(){
        $("#side-menu .selected").removeClass("selected");
        $("#header_explore").addClass("selected");
    }
    function showsearch(){
        $("#side-menu .selected").removeClass("selected");
        $("#header_search").addClass("selected");
    }
    function showsettings(){
        $("#side-menu .selected").removeClass("selected");
        $("#header_settings").addClass("selected");
    }

onclick 方法仅向菜单项添加/删除“selected”类。


如果您在处理程序中使用$.mobile.changePage(),同时又将页面ID放入链接的href属性中,我认为这可能会解释原因。请使用changePage()或href属性,但不要同时使用两者。 - John Goodsen
嗨John - 不,我只是使用href :/ - Alexander Casassovici
完成 :) 正如您所看到的,这很简单... - Alexander Casassovici
同时,“pop”和“flip”转换效果非常出色。 - Alexander Casassovici
更新:在安卓上,滑动操作非常流畅... - Alexander Casassovici
显示剩余3条评论
3个回答

3

1
嗨Spike - 我试过了,但不是这个 :( 我实际上不认为它在闪烁 :/ - Alexander Casassovici
嗯...抱歉我不知道。也许是与安卓模拟器有关?在iOS上会出现同样的问题吗? - Spike
我只在iOS上遇到问题,安卓没问题(而且在两种情况下模拟器和设备的表现都一样) - Alexander Casassovici
明白了。那我也不知道还能提什么建议了... 如果是我,我会从头开始,逐步添加每个代码片段,以找出导致故障的确切部分。 - Spike
我也遇到了完全相同的问题。 - Benjamin Oman

3

我和我的朋友们正在使用 JQuery 1.2。

解决这个问题的方法是添加 data-transition="none"。也许在移动端上看起来不太好,但可以消除闪烁问题。

希望这能帮到你。


0

我曾经遇到过同样的问题,但更糟糕的是,在Phonegap中包装Jquery移动应用程序时。页面转换不仅闪烁,而且UI完全崩溃。在此应用程序中,我使用了Jquery 1.8和Jquery mobile 1.2。

我尝试了SO上提出的大多数解决方案,但没有任何作用。然后我发现了Piotr Walczyszyn的this解决方案,一切都像梦想一样顺利!强烈推荐给所有同时使用Jquery mobile和Phonegap的人。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接