如何改进 Jquery 移动应用程序的页面转换?

2023-11-23

我在单个 HTML 页面中创建了一个小型 Jquery Mobile 应用程序。 我面临的问题是移动设备中页面转换的性能非常糟糕。当我滑动到下一页后,我最终等待了 3-4 秒,然后页面发生变化。 我有什么想法可以改进它吗?

这是代码:

<!DOCTYPE html> 
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>Multi-page template</title> 

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <link rel="stylesheet" href="http://jquerymobile.com/branches/tables/css/themes/default/jquery.mobile.css">  
    <link rel="stylesheet" href="http://jquerymobile.com/branches/tables/docs/_assets/css/jqm-docs.css">
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

</head> 


<body> 
    <form id="test" method="post">
        <!-- Start of page: #p01 -->
        <div data-role="page" id="p01" data-theme="b" data-prefetch>

            <div data-role="header" data-theme="a">
                <h1>Page 01 of 05</h1>
            </div><!-- /header -->

            <div data-role="content" >
                <h3>Please provide these details about the child</h3>
                <br/>
                <fieldset>
                    <label>Child's Full Name:</label>
                    <fieldset>
                        <input id = "p01_childFirstName_text" type="text" placeholder="First Name...">
                        <input id = "p01_childMidName_text" type="text" placeholder="Middle Name...">
                        <input id = "p01_childLastName_text" type="text" placeholder="Last Name...">
                    </fieldset>
                </fieldset>    
                <br/>
                <fieldset data-role="controlgroup" data-type="horizontal">
                    <legend>Child's Gender:</legend>
                        <input data-theme="a" type="radio" name="radio-choice" id="p01_childGenderMale_radio" value="choice-1" checked="checked" />
                        <label for="p01_childGenderMale_radio">Female</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p01_childGenderFemale_radio" value="choice-2"  />
                        <label for="p01_childGenderFemale_radio">Male</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p01_childGenderOther_radio" value="choice-3"  />
                        <label for="p01_childGenderOther_radio">Other</label>
                </fieldset>
                <br/>
                <fieldset>
                    <label for = "p01_childEthnGroup_text">Child's Ethnic Group or Race:</label>
                    <input id = "p01_childEthnGroup_text" type="text" placeholder="Ethnic Group...">
                </fieldset>
                <br/>
                <fieldset>
                    <label for="p01_childBirthDate_text">Child's Birth Date:</label>
                    <input id = "p01_childBirthDate_text" type="text" placeholder="DD/MM/YYYY">
                </fieldset>  
                <br/>
                <fieldset>
                    <label for="p01_childBirthDate_text">Child's Grade in School:</label>
                    <input id = "p01_childBirthDate_text" type="text" placeholder="DD/MM/YYYY">
                </fieldset>  
                <br/>
                <fieldset>
                    <label for="flip-1">Is the Child attending a School?</label>
                    <select name="flip-1" id="flip-1" data-role="slider" data-theme="a">
                        <option value="off">Yes</option>
                        <option value="on">No</option>
                    </select>   
                </fieldset>  

            </div><!-- /content -->

            <div data-role="footer" data-theme="a">
                    <p class = "footer_text"><small><em>Please swipe the page to the sides to go to the next page, or to return to the previous one.</em></small></p>
            </div><!-- /footer -->

        </div><!-- /page one -->

        <!-- Start of page: #p02 -->
        <div data-role="page" id="p02" data-theme="b" data-prefetch>

            <div data-role="header" data-theme="a">
                <h1>Page 02 of 05</h1>
            </div><!-- /header -->

            <div data-role="content" data-theme="b">    
                <h3>Please provide these details about the child's parent</h3>
                <p><small><em>Please enter these details even if the parents are not working now. 
                              Be specific - for example: auto mechanic, high school teacher, home maker, 
                              day labourer, lathe operator, army sergeant etc.
                </em></small></p>
                <br/>
                <fieldset>
                    <label for="p02_fatherWorkType_text">Father's Type of Work:</label>
                    <input id = "p02_fatherWorkType_text" type="text" placeholder="Type of Work...">
                </fieldset>  
                <br/>
                <fieldset>
                    <label for="p02_motherWorkType_text">Mother's Type of Work:</label>
                    <input id = "p02_motherWorkType_text" type="text" placeholder="Type of Work...">
                </fieldset>  
                <br/>
                <fieldset>
                    <label>Your Full Name:</label>
                    <fieldset>
                        <input id = "p02_userFirstName_text" type="text" placeholder="First Name...">
                        <input id = "p02_userMidName_text" type="text" placeholder="Middle Name...">
                        <input id = "p02_userLastName_text" type="text" placeholder="Last Name...">
                    </fieldset>
                </fieldset>    
                <br/>
                 <fieldset data-role="controlgroup" data-type="horizontal">
                    <legend>Your Gender:</legend>
                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userGenderMale_radio" value="choice-1" checked="checked" />
                        <label for="p02_userGenderMale_radio">Female</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userGenderFemale_radio" value="choice-2"  />
                        <label for="p02_userGenderFemale_radio">Male</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userGenderOther_radio" value="choice-3"  />
                        <label for="p02_userGenderOther_radio">Other</label>
                </fieldset>
                <br/>
                 <fieldset data-role="controlgroup">
                    <legend>Your Relation with the Child:</legend>
                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userRelationBio_radio" value="choice-1" checked="checked" />
                        <label for="p02_userRelationBio_radio">Biological Parent</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userRelationAdopt_radio" value="choice-2"  />
                        <label for="p02_userRelationAdopt_radio">Adoptive Parent</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userRelationStep_radio" value="choice-3"  />
                        <label for="p02_userRelationStep_radio">Step Parent</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userRelationGrand_radio" value="choice-3"  />
                        <label for="p02_userRelationGrand_radio">Grand Parent</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userRelationFoster_radio" value="choice-3"  />
                        <label for="p02_userRelationFoster_radio">Foster Parent</label>

                        <input data-theme="a" type="radio" name="radio-choice" id="p02_userRelationOther_radio" value="choice-3"  />
                        <label for="p02_userRelationOther_radio">Others (Please Specify)</label>
                        <input class= "p02_input_hidden_text" id = "p02_userRelationOther_text" type="text" placeholder="Specify Relation...">

                </fieldset>

            </div><!-- /content -->

            <div data-role="footer" data-theme="a">
                    <p class = "footer_text"><small><em>Please swipe the page to the sides to go to the next page, or to return to the previous one.</em></small></p>
            </div><!-- /footer -->

        </div><!-- /page two -->



         <!-- Start of page: #p05 -->
        <div data-role="page" id="p05" data-theme="b" data-prefetch>

            <div data-role="header" data-theme="a">
                <h1>Last Page</h1>
            </div><!-- /header -->

            <div data-role="content" data-theme="b">    
                <h2>Congratulations! You have filled out the Child Behaviour Checklist.</h2>
                <p><small><em>Please click on the "SUBMIT" button below to send us the checklist.</em></small></p>
                <br/>
                <br/>
                <br/>
                <button type="submit" data-theme="a" class="ui-btn-hidden" data-disabled="false">Submit</button>

            </div><!-- /content -->


        </div><!-- /page five -->

    </form>
    <style>
        .footer_text {
            text-align:center;
        }
    </style>

    <script>
    $( document ).on( 'mobileinit', function(){
        $.mobile.loader.prototype.options.text = "loading...";
        $.mobile.loader.prototype.options.textVisible = false;
        $.mobile.loader.prototype.options.theme = "a";
        $.mobile.loader.prototype.options.html = "";
    });
    $(document).on ('pageshow', function (e, data) {         
        // keep all previously-visited pages in the DOM. Remove this option later when application becomes large.
        $.mobile.page.prototype.options.domCache = true;

        var activePage = $.mobile.activePage.attr("id");
        var previousPage = (parseInt(activePage.slice(1,3))-1).toString();
        var nextPage = (parseInt(activePage.slice(1,3))+1).toString();

        window.myActivePage = activePage;
        window.myPreviousPage = "#p0" + previousPage;
        window.myNextPage = "#p0" + nextPage;

    });
    // page navigation on using swipes
    $(document).on('swipeleft',function(event, ui){
            $.mobile.changePage(window.myNextPage, { transition: "slide"});
        });
    $(document).on('swiperight',function(event, ui){
            $.mobile.changePage(window.myPreviousPage, { transition: "slide", reverse:true});
        });

    // Code to show and hide fields. Spaghetti code. Refactor this when working on actual app.
    $(document).ready(function() {
        $('[id=p02_userRelationOther_text]').hide()
        $('[type=radio]').click(function(eventName) {
            if (this.id == 'p02_userRelationOther_radio') {
                $('[id=p02_userRelationOther_text]').show('slow')
            }
            else {
                $('[id=p02_userRelationOther_text]').hide('slow')
            }
        });

        $('[id=p03_noSports_check]').click(function(eventName) {
            if ($('[id=p03_noSports_check]').is(":checked")) {
                $('[class=p03_hidden_container]').hide('slow')
            }
            else {
            $('[class=p03_hidden_container]').show('slow')
            }
        });

        $('[id=p04_noHobby_check]').click(function(eventName) {
            if ($('[id=p04_noHobby_check]').is(":checked")) {
                $('[class=p04_hidden_container]').hide('slow')
            }
            else {
            $('[class=p04_hidden_container]').show('slow')
            }
        });
    });
    </script>
</body>

</html>

有以下几种方法:

  • 如果您正在使用!具有多个页面的 html 文件,将它们包装到单个 div 中:

    <div id="container"/>
    

并设置这个CSS:

    body {
        margin: 0;
    }

    #container {
        position: absolute;
        width: 100%;
        height: 100%;
    }

js code:

    $(document).one("mobileinit", function () {
        $.mobile.pageContainer = $('#container');
        $.mobile.defaultPageTransition = 'slide';
    });

有关此方法的更多信息可以在这里找到:http://outof.me/fixing-flickers-jumps-of-jquery-mobile-transitions-in-phonegap-apps/

  • 其他常见的解决方案是设置此 css: .ui-页面{ -webkit-backface-visibility:隐藏; }

该解决方案的问题在于它破坏了表单上的选择列表。

  • 关闭它们:

    $(document).bind("mobileinit", function(){
        $.mobile.defaultDialogTransition = "none";
        $.mobile.defaultPageTransition = "none";
    });
    
  • 在 jquery 移动应用程序上使用 fastclick 来加速点击事件,从而加快页面转换。单击事件最多可在页面转换中添加 300 毫秒。这个插件会做更多的事情,但对于你的情况来说它就足够了。

Link: https://github.com/drowne/jquery.mobile.fastclick

  • 如果您不需要其他插件,您仍然可以通过从页面更改按钮中删除 href 来实现更快的页面转换,然后执行以下操作:

    <a class="ui-btn-left" data-icon="arrow-l" href="#" data-theme="a" id="back-btn">Back</a>
    
    $('#back-btn').bind('touchstart', function(e) {
        $.mobile.changePage("#pageID");
    });
    

如果您知道用户不会滚动,则 touchstart(或 touchend)事件效果很好。这实际上就是移动设备上单击事件需要很长时间才能解析的原因,设备正在等待查看用户是否正在滚动或单击。所以touchstart不应该像普通的click/tap事件那样有延迟。

我希望其中一些解决方案能够帮助您。请注意,这些都不是万无一失的解决方案,它们也有自己的缺点。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何改进 Jquery 移动应用程序的页面转换? 的相关文章

  • zone.js:140未捕获类型错误:无法读取属性“删除”

    我是 kendo ui 的新手 我在小提琴中开发了原型 删除确认窗口在那里工作正常 但是当我集成到我的代码库中时 我收到错误 Cannot read property remove at the line pai to delete rem
  • PHP 多个 Ajax 请求:第一个请求阻止第二个请求

    我在一页上有 2 个 ajax 请求 我运行了第一个请求并单独启动了第二个请求 但第二个在第一个运行后停止工作 第一次结束后继续 第一个请求需要很长时间 大约 30 60 秒 此时我需要第二个请求来显示日志第一个请求发生的情况 我尝试使用
  • 将 jQuery 与 Selenium WebDriver 结合使用 - 如何将 JSON 对象转换为 WebElement?

    我正在使用 Selenium WebDriver 我想执行 jQuery 代码来查找一些元素 我的代码如下 public function uploadGrantDoc script return itemlist grant file u
  • IE提示打开或保存服务器的json结果

    兼容模式下的Internet Explorer通过ajax回调方法从服务器获取数据 如果我想保存数据或打开数据 会弹出一个对话框 如何摆脱它 客户说 ajax type POST data UIdlgHolder gt form seria
  • select2 验证 - 选择至少一个值

    我在用select2 http ivaynberg github io select2 and jQuery 验证 http jqueryvalidation org 插件 select2 的 HTML div class form gro
  • jQuery:向左滑动和向右滑动

    我见过slideUp and slideDown在 jQuery 中 左右滑动的功能 方式怎么样 您可以使用 jQuery UI 中的附加效果来做到这一点 详情请参阅此处 http docs jquery com UI Effects Sl
  • YouTube 点击时禁用 HTML5

    有没有办法让我们通过javascript禁用HTML5视频的 播放 暂停 点击全屏 功能 然后在我们再次需要时将其放回去 我不知道你是否可以禁用它们 但你可以使用 css 删除它们 video webkit media controls f
  • 请求 jquery.min.map 文件时出现引用 404 错误

    现在 当浏览器请求 jquery min map 时 我会收到此 404 错误 有趣的是 我从未将此文件添加到我的解决方案中 谁能向我解释如何消除这个错误 我不知道该文件在哪里被引用 因为我没有添加对此文件的引用 Request URL h
  • 有什么方法可以取消/停止/中止 getScript 调用吗?

    所以 我一直在寻找 似乎没有一种方法可以在脚本调用完成后真正中止 取消 停止脚本调用 我发现必须使用延迟加载来解决对第三方的无响应脚本调用有点奇怪 使用 json ajax 我当然可以超时 太棒了 但对于脚本调用 就没有这样的运气了 我认为
  • 使用 jQuery 在页面加载时将字符串添加到 url?

    我试图在页面加载时将此特定字符串添加到我的网址末尾 aa campaign f45632 http examplesite com test html http examplesite com test html 它用于营销和跟踪 我试过这
  • jQuery 的简单日历网格

    我发现的大多数可爱的日历组件对于我的简单要求来说都太复杂了 我需要显示月份网格 并指示是否已预订个别日期 我不需要每天处理多个活动 等等 我想我可以调整其中一个以始终将预订扩展为全天活动 读者对此有何建议 我的目标是显示住宿加早餐预订的日期
  • 如何将 jquery 应用于具有相同 id 属性的所有元素?

    如何将 jquery 应用于具有相同 id 属性的所有元素 我想申请focus and blur 函数在一个textarea具有相同 id 的元素 正确的答案是 id yourID doSomething 对于任何代码 例如
  • 如何使用jquery格式化数字

    我正在尝试删除 之后的数字 然后我想格式化数字 16810900 211233 喜欢这个 16 810 900 但我不知道该怎么做 这是我的 html 是这样的 div class main p class active 10200 00
  • 在 jQuery 中获取 Json 数据

    没有一个清晰的示例解释如何尽可能简单地拉取 json 数据 我有一个有效的 json 我需要使用 jQuery 检索它 我的 json 输出如下 title blog entries items title Can Members of t
  • 如何获得相对于特定父级的偏移量?

    我想获取元素相对于的偏移量特定的父母不是直接的 也不是文档 我在互联网上查找并找到了offset http api jquery com offset and position http api jquery com position jQ
  • jQuery 中如何判断 JSON 对象是否为空

    我有以下 JSON meta limit 20 next null offset 0 previous null total count 0 objects 我对对象感兴趣 我想知道对象是否为空并显示警报 像这样的东西 success fu
  • Javascript“命名空间”和 jQuery AJAX

    我正在使用此处列出的建议 http www odetocode com articles 473 aspx http www odetocode com articles 473 aspx 使用模拟的JavaScript AJAX网络聊天系
  • 哪些控件触发了 Page.IsValid = false?

    两件事情 是否可以通过 Jquery 设置 Page IsValid Is Valid 属性 以便我不必使用 aspx 验证器 据我了解 IsValid 属性是只读的 当验证器进入时 是否可以通过 Jquery 当然 找出哪些控件导致验证失
  • jQuery 单击附加元素不起作用

    我有一个数组 我正在从 Array 获取数据并在 jQuery Append to list 中使用它 但是当我单击列表项时 它只显示最后一个元素 var array 1 2 7 3 4 8 5 6 9 for var i 0 i lt a
  • jQuery Draggable:可拖动框越过容器 - bug?

    Try this http jsfiddle net QhVNr code HTML div class draggable container div class draggable div class exp div div div C

随机推荐

  • 从网络共享运行“部分受信任”的 .NET 程序集

    当我尝试运行 NET 程序集时 boo exe 从网络共享 映射到驱动器 它会失败 因为它仅部分受信任 Unhandled Exception System Security SecurityException That assembly
  • 为什么 C# 扩展方法必须在静态类中定义? [复制]

    这个问题在这里已经有答案了 我知道 C 扩展方法必须是静态的 我不明白的是为什么这些扩展不能在非静态类或通用类中定义 更新 我对这个设计决策背后的原因感兴趣 这更多的是一种观察而不是答案 但是 当您调用实例方法时 对您正在调用的对象的引用将
  • 使用 mongoDB 将嵌入文档与父字段进行比较

    考虑以下集合 其中父文档有一个amount具有值的字段100000并且有一个嵌入的具有相同字段的文档数组amount和相同的值 id ObjectId 5975ce5f05563b6303924914 amount 100000 offer
  • 通过NAT访问SQL Server实例

    我正在尝试访问通过 IP NAT 映射公开的 SQL Server 所有端口均开放 我不知道 NAT 的详细信息 是否相关 因为那是公司其他地方隐藏在一堆繁文缛节中的内容 这就是我的想法 当您尝试访问 SQL Server 的命名实例时 客
  • 内容://sms/sent/ 不起作用

    这是短信观察者代码 我只需要检查发送的短信 当我使用content sms 我得到结果了 但为什么我使用时没有得到结果content sms sent 我使用的是安卓2 1 import android app Service import
  • 如何获取字符串的宽度(以像素为单位)?

    我正在使用 wxPython 的 HyperTreeList 我想将列宽设置为恰好等于其中最大字符串的长度 为了实现这一点 我想将 python 字符串大小转换为像素 例如 如果我们有一个像这样的字符串 str python len str
  • 与所有子域 codeigniter 共享会话数据

    我正在尝试使用一个session我所有子域的数据 我创建了一个subdomain in cpanel像这样 mydomain in and my mydomain in使用与我相同的路径mydomain in例子 mydomain in使用
  • 如何在我的电脑上运行php文件

    谁能告诉我如何在我的系统上本地运行 php 文件 目前我正在使用服务器来运行文件 我知道要安装 php 和 Apache 我需要查看该程序的输出 例如 如果我需要更多内容 您能告诉我如何运行这些文件吗 php 有一个简单的方法来运行轻量级服
  • 在 QMainWindow 中选择“中央小部件”的规则是什么?为什么它很重要?

    我明白设置CentralWidget需要在Q主窗口乍一看 中央小部件的含义似乎非常不言自明 但有没有更严格的定义 central 比如说 我有几个同样重要的小部件位于窗口的中央区域 我是否应该始终找到一种方法将它们分组在一起并将该组设置为中
  • PHP filemtime 函数 - “统计失败”

    我的 PHP filemtime 函数有问题 在我的网络应用程序中 我使用带有缓存选项的 Smarty 模板引擎 在我的网络应用程序中 我可以执行一些会产生错误的操作 但让我们只关注一个操作 当我单击页面上的链接时 某些内容会更新 我可以单
  • Linux:是否有从套接字读取或接收超时?

    如何尝试从套接字读取超时数据 我知道 select pselect poll 有一个超时字段 但是使用它们会禁用 tcp reno 堆栈中的 tcp 快速路径 我唯一的想法是在循环中使用 recv fd MSG DONTWAIT 您可以使用
  • 如何拦截CallKit来电屏幕发送的“消息”?

    我正在使用 iOS 10 的 CallKit 来接听来电 我的应用程序中的呼叫不是来自 电话号码 或 电子邮件地址 而是来自我的协议中的内部标识符 因此 我报告来电CXHandleType of CXHandleTypeGeneric 并不
  • 如何在 Linux 服务器上从 PDF 文件创建缩略图/屏幕截图?

    我想创建 PDF 文件的缩略图 以便能够在网站上显示 PDF 文件的简短预览 我用 ImageMagick 尝试过 不幸的是 结果不太令人满意 生成的图像非常模糊 缩略图示例 模糊 原始PDF 见评论 命令 convert thumbnai
  • ETL SSIS:将错误行重定向到单独的表

    我正在开发一个包 其中包含一个源 大约 80 个查找和 1 个目标 源表中的数据不够一致 因此我的包经常失败 有没有一种方法可以传输将它们插入目标表时给出的所有行 例如 我在 Source 中有 5 行 其中第一行和第四行会出错 现在的结果
  • 将2个数组合并成一个多维数组?

    这是基于我最后一个问题 我有这些数组 var array1 new Array Pepsi Coke Juice Water var array2 new Array 35 17 21 99 我想将它们组合起来形成一个多维数组 如下所示 P
  • 在 Powershell 中测试 null:为什么测试空数组的行为与空字符串不同?

    考虑这段代码 Type array v eq null v eq null ne null v ne null Type string v eq null v eq null ne null v ne null 产生以下结果 Type ar
  • 目标缩放导致 Scikit-learn SVM 回归崩溃

    训练 SVM 回归时 通常建议在训练之前缩放输入特征 但如何扩大目标呢 通常这不被认为是必要的 而且我看不出有什么充分的理由说明为什么有必要这样做 然而 在 scikit learn 的 SVM 回归示例中 http scikit lear
  • 如何连接已知长度的数组?

    我有两个已知长度的数组 let left u8 2 1 2 let right u8 3 3 4 5 我的第一次尝试 let whole u8 5 left right 失败并出现错误 error E0369 cannot add u8 2
  • xlwt 即时写入 Excel 工作表

    我习惯于通过以下方式创建电子表格 wbk xlwt Workbook earnings tab wbk add sheet EARNINGS wbk save filepath 有没有什么方法可以不保存到文件路径 而是将其即时写入下载文件的
  • 如何改进 Jquery 移动应用程序的页面转换?

    我在单个 HTML 页面中创建了一个小型 Jquery Mobile 应用程序 我面临的问题是移动设备中页面转换的性能非常糟糕 当我滑动到下一页后 我最终等待了 3 4 秒 然后页面发生变化 我有什么想法可以改进它吗 这是代码