Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 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 Answer

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[6] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...