Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

javascript - Closing jQuery Mobile Panel

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...