jQuery Mobile panel
Panels in jQuery Mobile stretch from the left to the right of the screen.
Create a panel by adding the data-role="panel" attribute to the <div> element with the specified id.
Add HTML tags in <div> to display your panel content:
<div data-role="panel" id="myPanel"> <h2>面板标题..</h2> <p>文本内容..</p> </div>
Note: The panel tag must be placed in the header, content, and bottom before or after the page.
To access the panel, you need to create a link to the panel<div> id. Click the link to open the panel:
<a href="#myPanel" class="ui-btn ui-btn-inline">打开面板</a>
Simple panel example
Instance
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="panel" id="myPanel"> <h2>面板头部</h2> <p>你可以通过点击面板外部区域或按下 Esc 键或滑动来关闭面板。</p> </div> <div data-role="header"> <h1>页面头部</h1> </div> <div data-role="main" class="ui-content"> <p>点击下面按钮打开面板。</p> <a href="#myPanel" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">打开面板</a> </div> <div data-role="footer"> <h1>页面底部</h1> </div> </div> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
Close the panel
You can close the panel by clicking outside the panel or pressing the Esc key or sliding. You can disable sliding and clicking to close the panel by using the data-* attributes:
Properties | Value | Description | Example |
---|---|---|---|
data-dismissible | true | false | Specifies whether the panel can be opened by clicking outside the panel area closure. | Try it |
data-swipe-close | true | false | Specify whether it can pass Slide to close. | Try it |
You can use the button to close the panel: just add the data-rel="close" attribute to the <div> of the panel . For performance reasons, we need the href attribute of the key to close the link to point to the ID of the page.
Instance
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="panel" id="myPanel"> <h2>面板头部</h2> <p>你可以使用按下 Esc 键、点击面板外部区域、通过滑动或点击下面按钮来关闭面板:</p> <a href="#pageone" data-rel="close" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left">关闭面板</a> </div> <div data-role="header"> <h1>页面头部</h1> </div> <div data-role="main" class="ui-content"> <p>点击下面按钮打开面板。</p> <a href="#myPanel" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">打开面板</a> </div> <div data-role="footer"> <h1>页面底部</h1> </div> </div> </body> </html>
Run Instance»
Click the "Run Instance" button View online examples
Panel display
You can control how the panel is displayed by using the data-display attribute:
Attribute value | Description |
---|---|
data-display="overlay" | Display panel over content |
data-display="push" | is to "push" panels and pages at the same time. |
data-display="reveal" | Default value, slide the page out of the screen like a slide and display the panel |
Instance
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="panel" id="overlayPanel" data-display="overlay"> <h2>覆盖面板</h2> <p>你可以使用按下 Esc 键、点击面板外部区域、通过滑动或点击下面按钮来关闭面板:</p> <a href="#pageone" data-rel="close" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left">关闭面板</a> </div> <div data-role="panel" id="revealPanel" data-display="reveal"> <h2>滑出面板</h2> <p>你可以使用按下 Esc 键、点击面板外部区域、通过滑动或点击下面按钮来关闭面板:</p> <a href="#pageone" data-rel="close" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left">关闭面板</a> </div> <div data-role="panel" id="pushPanel" data-display="push"> <h2>推动面板</h2> <p>你可以使用按下 Esc 键、点击面板外部区域、通过滑动或点击下面按钮来关闭面板:</p> <a href="#pageone" data-rel="close" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left">关闭面板</a> </div> <div data-role="header"> <h1>页面头部</h1> </div> <div data-role="main" class="ui-content"> <p>点击以下按钮查看面板的不同展示方式。</p> <a href="#overlayPanel" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">覆盖面板</a> <a href="#revealPanel" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">滑出面板</a> <a href="#pushPanel" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">推动面板</a> </div> <div data-role="footer"> <h1>页面底部</h1> </div> </div> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Panel positioning
By default, the panel will be displayed on the left side of the screen. If you want the panel to appear on the right side of the screen, you can specify the data-position="right" attribute.
Instance
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="panel" id="myPanel" data-position="right"> <h2>面板头部</h2> <p>你可以使用按下 Esc 键、点击面板外部区域、通过滑动或点击下面按钮来关闭面板:</p> <a href="#pageone" data-rel="close" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left">关闭面板</a> </div> <div data-role="header"> <h1>页面头部</h1> </div> <div data-role="main" class="ui-content"> <p>打开下面按钮显示面板</p> <a href="#myPanel" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">打开面板</a> </div> <div data-role="footer"> <h1>页面底部</h1> </div> </div> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
You can specify that the panel's content scrolls based on page scrolling. By default the panel scrolls with the page (but the panel's content remains at the top of the page). If you need to fix the content of the panel and not scroll with the scrolling of the page, you can add the data-position-fixed="true" attribute to the panel:
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="panel" id="myPanelDefault"> <h2>面板头部</h2> <p>你可以使用按下 Esc 键、点击面板外部区域、通过滑动或点击下面按钮来关闭面板:</p> <a href="#pageone" data-rel="close" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left">关闭面板</a> </div> <div data-role="panel" id="myPanelFixed" data-position-fixed="true"> <h2>Panel Header</h2> <p>你可以使用按下 Esc 键、点击面板外部区域、通过滑动或点击下面按钮来关闭面板:</p> <a href="#pageone" data-rel="close" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left">关闭面板</a> </div> <div data-role="header"> <h1>页面头部</h1> </div> <div data-role="main" class="ui-content"> <p>点击两个按钮并滚动查看效果。</p> <a href="#myPanelDefault" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">打开默认面板</a> <a href="#myPanelFixed" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">打开面板使用 data-position-fixed="true"</a> <p><b>提示:</b>要查看 data-position-fixed="true" 属性的效果,如果未出现滚动条可以重置窗口大小。</p> <p>用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。用于滚动的文本。。。。</p><br> </div> <div data-role="footer"> <h1>页面底部</h1> </div> </div> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance