<small id='NPQZf'></small><noframes id='NPQZf'>

    <tfoot id='NPQZf'></tfoot>
  1. <legend id='NPQZf'><style id='NPQZf'><dir id='NPQZf'><q id='NPQZf'></q></dir></style></legend>
    <i id='NPQZf'><tr id='NPQZf'><dt id='NPQZf'><q id='NPQZf'><span id='NPQZf'><b id='NPQZf'><form id='NPQZf'><ins id='NPQZf'></ins><ul id='NPQZf'></ul><sub id='NPQZf'></sub></form><legend id='NPQZf'></legend><bdo id='NPQZf'><pre id='NPQZf'><center id='NPQZf'></center></pre></bdo></b><th id='NPQZf'></th></span></q></dt></tr></i><div id='NPQZf'><tfoot id='NPQZf'></tfoot><dl id='NPQZf'><fieldset id='NPQZf'></fieldset></dl></div>

      <bdo id='NPQZf'></bdo><ul id='NPQZf'></ul>

      当 jquerymobile 中的窗口大小更改时更改 div id 和属

      时间:2023-10-04
    1. <legend id='jk70I'><style id='jk70I'><dir id='jk70I'><q id='jk70I'></q></dir></style></legend>
      <tfoot id='jk70I'></tfoot>

      1. <i id='jk70I'><tr id='jk70I'><dt id='jk70I'><q id='jk70I'><span id='jk70I'><b id='jk70I'><form id='jk70I'><ins id='jk70I'></ins><ul id='jk70I'></ul><sub id='jk70I'></sub></form><legend id='jk70I'></legend><bdo id='jk70I'><pre id='jk70I'><center id='jk70I'></center></pre></bdo></b><th id='jk70I'></th></span></q></dt></tr></i><div id='jk70I'><tfoot id='jk70I'></tfoot><dl id='jk70I'><fieldset id='jk70I'></fieldset></dl></div>
            <tbody id='jk70I'></tbody>

            • <bdo id='jk70I'></bdo><ul id='jk70I'></ul>
            • <small id='jk70I'></small><noframes id='jk70I'>

              • 本文介绍了当 jquerymobile 中的窗口大小更改时更改 div id 和属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我当前的代码是

                测试

                当窗口大小小于640px时,我如何将其更改为:

                测试

                data-role="panel" 是 jquerymobile 代码.问题集中在我们如何将 data-role="panel" 属性添加到 div 上.谢谢!

                您可以在 http://jsbin.com/wakagumu/11/edit.如果成功,将 id="column-left" 更改为 data-role="panel" id="left-panel" 后,测试FIRST"将消失.

                解决方案

                更改属性不会将div转换为面板,您需要初始化 手动.在 jQuery Mobile 1.3 中,您应该在动态附加 panel 时使用 .trigger("pagecreate")初始化它.

                下面的解决方案创建一个面板并在页面的宽度较小时移动内容 div的元素;它删除 panel 并将 content div 的元素返回到它们的原始位置.此外,它会在 header 内创建一个按钮来打开 面板.它可以用于任何页面事件以及窗口的throttledresizeorientationchange.

                $(window).on("throttledresize", function () {var activePage = $.mobile.activePage;if ($(window).width() <500 && activePage.find("[data-role=panel]").length === 0) {/* 创建按钮 */var button = $("", {"数据角色": "按钮","数据图标": "条","id": "panelBtn","数据主题": "e",课程:ui-btn-left"}).text("面板");/* 添加点击监听器以打开面板并将其附加到标题 */activePage.find(".ui-header").append($(button).on("click", function () {$("#left-panel").panel("open");}));/* 保存菜单 */var menu = $("#menu");/* 创建一个面板附加菜单创建页面 */activePage.prepend($("

                ", {id:左面板",数据角色":面板",数据位置":左",数据显示":推送"}).append($("

                ", {课程:ui-panel-inner"}).append(menu))).trigger("pagecreate");}if ($(window).width() > 500 && activePage.find("[data-role=panel]").length === 1) {/* 移除面板和按钮返回菜单到内容 div */如果(activePage.hasClass(ui-page-panel-open")){activePage.find("[data-role=panel]").panel("close").on("panelclose", function () {var menu1 = activePage.find("[数据角色=面板] #menu");activePage.find("[data-role=content]").append(menu1);activePage.find("[数据角色=面板]").remove();activePage.find("#panelBtn").remove();activePage.trigger("pagecreate");});} 别的 {var menu1 = activePage.find("[数据角色=面板] #menu");activePage.find("[data-role=content]").append(menu1);activePage.find("[数据角色=面板]").remove();activePage.find("#panelBtn").remove();activePage.trigger("pagecreate");}}});

                <块引用>

                演示

                My current code is

                <div id="column-left">
                     Test
                </div>
                

                When the window size is smaller than 640px, how can I change it as:

                <div data-role="panel" id="left-panel" data-position="left">
                     Test
                </div>
                

                data-role="panel" is jquerymobile code. The question is focusing on how we can add the data-role="panel" attribute to the div. Thanks!

                You may test your code in http://jsbin.com/wakagumu/11/edit. If it success, the test "FIRST" will disappear after changing the id="column-left" to data-role="panel" id="left-panel".

                解决方案

                Changing attributes won't convert a div into a panel, you need to initialize it manually. In jQuery Mobile 1.3, you should use .trigger("pagecreate") when appending a panel dynamically in order to initialize it.

                The below solution creates a panel and moves content div's elements when page's width is small; and it removes panel and returns content div's element to their original position. Also, it creates a button inside header to open the panel. It can be used in any page events as well as on window's throttledresize and orientationchange.

                $(window).on("throttledresize", function () {
                    var activePage = $.mobile.activePage;
                    if ($(window).width() < 500 && activePage.find("[data-role=panel]").length === 0) {
                       /* create button */
                        var button = $("<a/>", {
                            "data-role": "button",
                                "data-icon": "bars",
                                "id": "panelBtn",
                                "data-theme": "e",
                            class: "ui-btn-left"
                        }).text("Panel");
                        /* add click listener to open panel 
                           and append it to header         */
                        activePage.find(".ui-header").append($(button).on("click", function () {
                            $("#left-panel").panel("open");
                        }));
                
                        /* save menu */
                        var menu = $("#menu");
                        /* create a panel 
                           append menu
                           create page    */
                        activePage.prepend($("<div/>", {
                            id: "left-panel",
                                "data-role": "panel",
                                "data-position": "left",
                                "data-display": "push"
                        }).append($("<div/>", {
                            class: "ui-panel-inner"
                        }).append(menu))).trigger("pagecreate");
                    }
                
                    if ($(window).width() > 500 && activePage.find("[data-role=panel]").length === 1) {
                        /* remove panel and button
                           return menu to content div */
                        if (activePage.hasClass("ui-page-panel-open")) {
                            activePage.find("[data-role=panel]").panel("close").on("panelclose", function () {
                                var menu1 = activePage.find("[data-role=panel] #menu");
                                activePage.find("[data-role=content]").append(menu1);
                                activePage.find("[data-role=panel]").remove();
                                activePage.find("#panelBtn").remove();
                                activePage.trigger("pagecreate");
                            });
                        } else {
                            var menu1 = activePage.find("[data-role=panel] #menu");
                            activePage.find("[data-role=content]").append(menu1);
                            activePage.find("[data-role=panel]").remove();
                            activePage.find("#panelBtn").remove();
                            activePage.trigger("pagecreate");
                        }
                    }
                });
                

                Demo

                这篇关于当 jquerymobile 中的窗口大小更改时更改 div id 和属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么我看到“未定义"的值?当我在 jQuery M 下一篇:从数据库获取相似的经纬度

                相关文章

                最新文章

                  <tfoot id='ARNmO'></tfoot>

                1. <small id='ARNmO'></small><noframes id='ARNmO'>

                2. <i id='ARNmO'><tr id='ARNmO'><dt id='ARNmO'><q id='ARNmO'><span id='ARNmO'><b id='ARNmO'><form id='ARNmO'><ins id='ARNmO'></ins><ul id='ARNmO'></ul><sub id='ARNmO'></sub></form><legend id='ARNmO'></legend><bdo id='ARNmO'><pre id='ARNmO'><center id='ARNmO'></center></pre></bdo></b><th id='ARNmO'></th></span></q></dt></tr></i><div id='ARNmO'><tfoot id='ARNmO'></tfoot><dl id='ARNmO'><fieldset id='ARNmO'></fieldset></dl></div>
                  <legend id='ARNmO'><style id='ARNmO'><dir id='ARNmO'><q id='ARNmO'></q></dir></style></legend>

                    • <bdo id='ARNmO'></bdo><ul id='ARNmO'></ul>