Closing jQuery Mobile Panel

非 Y 不嫁゛ 提交于 2019-12-29 07:47:06

问题


I have a panel with links like this

Page1
Page2
Page3

If I am currently on Page1 and open the panel, the panel is not closed when I select Page1 again. I have checked jQuery mobile panel documentation, and has the same behaviour (if you open the panel an click on "Panels", the panel will stay open.

Is there a way to close the panel if same page link is selected?

Edit: jQuery Mobile version: 1.3.2 jQuery version: 1.9.1


回答1:


You do something like this

$(document).on("pageinit", function () {
  $("[data-role=panel] a").on("click", function () {
    if($(this).attr("href") == "#"+$.mobile.activePage[0].id) {
      $("[data-role=panel]").panel("close");
    }
  });
});

Update: For jQM >= 1.4 use $.mobile.pageContainer.pagecontainer("getActivePage") instead of $.mobile.activePage.

Demo: http://jsfiddle.net/Palestinian/k89A5/1/




回答2:


only add data-rel="close"

 <li class="liPanel"><a href="javascript:void(0);" **data-rel="close"** class="ui-btn ui-shadow ui-corner-all ui-btn-icon-right ui-icon-info">Faqs</a>
</li>


来源:https://stackoverflow.com/questions/20478094/closing-jquery-mobile-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!