Phonegap/jquery 移动幻灯片转换在第一次调用时无法正常工作 [英] Phonegap / jquery mobile slide transition not workign properly on first call

查看:15
本文介绍了Phonegap/jquery 移动幻灯片转换在第一次调用时无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个尴尬的视觉故障.在更改应用程序页面时,我想要一个很好的过渡.不幸的是,我第一次切换到另一个页面时,不是将当前页面滑出并滑入新页面,而是立即将当前页面替换为新页面然后滑出.当第一页不在视图中时,将显示新页面.然而,第二次,它就像一个魅力!

这是在带有 jQ​​uery Mobile + PhoneGap 的 iphone 上运行

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

 <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 id="slide_mask"><!-- 登录页面开始--><div data-role="page" id="登录"><div id="home_frame"><div id="home_logo"></div><div id="home_fblogin" onclick="login()"></div><div class="home_login"><p>电子邮件:<input type="text" name="user[email]" size="30"/></p><p>密码:<input type="password" name="user[password]" size="30"/></p><button onclick="show_page_home();">登录</button>

<!-- 登录页面结束--><!-- 登录页面开始--><div data-role="page" id="dives" class="right_pane"><p>我的潜水!</p></div><!--/content --><div data-role="page" id="explore" class="hidden right_pane"><p>我的探索!</p></div><!--/content --><div data-role="page" id="search" class="hidden right_pane"><p>我的搜索!</p></div><!--/content --><div data-role="page" id="settings" class="hidden right_pane"><p>我的设置!</p><button onclick="logout_db();">注销</button></div><!--/content --><!-- 登录页面结束-->

<div id="日志"></div><div id="数据"></div>

以及相关的 CSS:

 body {margin: 0;字体:18px Helvetica;文本对齐:居中;背景色:#000;背景:url(../img/bg_big.png) 重复;-webkit-user-select:无;/* 防止复制粘贴所有元素 */}#container { 宽度:320px;高度:460px;溢出:隐藏;}输入{-webkit-user-select:文本;/* 为具有此类的元素启用复制粘贴 */}{-webkit-user-select: none;/* 防止所有元素的复制粘贴 */}跨{-webkit-user-select:无;/* 防止所有元素的复制粘贴 */}#side-menu {z-index: 1000 !important;位置:固定;高度:460px;宽度:56.5px;背景: url(../img/bg_big.png) 不重复;显示:内联块;溢出:隐藏;顶部:0px;左:0px;}#header_top {background: url(../img/header/header_top.png) no-repeat;背景尺寸:56.5px 48.96px;宽度:56.5px;高度:48.96px;显示:块;}#header_dives {background: url(../img/header/dives.png) no-repeat;背景尺寸:56.5px 51.75px;宽度:56.5px;高度:51.75px;显示:块;}#header_dives.selected{background: url(../img/header/dives_selected.png) no-repeat;}#header_spacer1{background: url(../img/header/header_space1.png) 不重复;背景尺寸:56.5px 13.9px;宽度:56.5px;高度:13.9px;显示:块;}#header_explore{background: url(../img/header/explore.png) no-repeat;背景尺寸:56.5px 51.75px;宽度:56.5px;高度:51.75px;显示:块;}#header_explore.selected{background: url(../img/header/explore_selected.png) 不重复;}#header_spacer2{background: url(../img/header/header_space2.png) 不重复;背景尺寸:56.5px 15.33px;宽度:56.5px;高度:15.33px;显示:块;}#header_search{background: url(../img/header/search.png) 不重复;背景尺寸:56.5px 51.75px;宽度:56.5px;高度:51.75px;显示:块;}#header_search.selected{background: url(../img/header/search_selected.png) 不重复;}#header_spacer3{background: url(../img/header/header_space3.png) 不重复;背景尺寸:56.5px 17.73px;宽度:56.5px;高度:17.73px;显示:块;}#header_settings{background: url(../img/header/settings.png) no-repeat;背景尺寸:56.5px 51.75px;宽度:56.5px;高度:51.75px;显示:块;}#header_settings.selected{background: url(../img/header/settings_selected.png) no-repeat;}#header_bottom{background: url(../img/header/header_bottom.png) 不重复;背景尺寸:56.5px 160px;宽度:56.5px;高度:160px;显示:块;}.hidden {显示:无;}.right_pane{width: 263.5px !important;背景: url(../img/right_bg.png) 不重复;背景尺寸:263.5px 460px;宽度:263.5px;高度:460px;左:56.5px!重要;}#slide_mask{ 显示:内联块;溢出:隐藏;左边距:56.5px;宽度:263.5px;高度:460px;顶部:0;}

还有一点点JS:

/////////////////////////////////////菜单机制/////////////////////////////////////函数 showdives(){$("#side-menu .selected").removeClass("selected");$("#header_dives").addClass("selected");}功能显示探索(){$("#side-menu .selected").removeClass("selected");$("#header_explore").addClass("selected");}功能显示搜索(){$("#side-menu .selected").removeClass("selected");$("#header_search").addClass("selected");}功能显示设置(){$("#side-menu .selected").removeClass("selected");$("#header_settings").addClass("selected");}

onclick 方法仅在菜单项中添加/删除选定"类.

解决方案

我相信人们将其称为闪烁",因此您在搜索时会获得更好的结果.环顾四周,看起来你的问题在android上很常见,可以通过添加以下CSS来解决:

.ui-page {-webkit-backface-visibility:隐藏;}

这里有一些参考:

I have an awkward visual glitch. I want a nice transition when changing pages on an app. Unfortunately, the first time I change to another page, instead of sliding the current page out and the new page in, the current page is immediately replaced by the new page and then slides out. When the first page is out of view, the new page is shown. However, the second time around, it works like a charm!

This is running on iphone with jQuery Mobile + PhoneGap

I made a video to help clarify the issue: 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>

And the relevant 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;}

and the bit of 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");
    }

The onclick methods only add/remove the "selected" class to/from the menu items.

解决方案

I believe people refer to this as "flickering", so you'll have better results when you search for that. After looking around, it looks like your problem is common on android and can be solved by adding the following CSS:

.ui-page {
    -webkit-backface-visibility: hidden;
}

Here are a few references:

这篇关于Phonegap/jquery 移动幻灯片转换在第一次调用时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆