Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

395 lines (265 sloc) 23.163 kb
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Docs - Slide Panel</title>
<link rel="stylesheet" href="../../css/themes/default/jquery.mobile.css" />
<link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
<script src="../../js/jquery.js"></script>
<script src="../../docs/_assets/js/jqm-docs.js"></script>
<script src="../../js/"></script>
</head>
<body>
<div data-role="page" class="ui-responsive-panel">
<style>
.panel-content { padding:15px; }
</style>
<!-- defaultpanel -->
<div data-role="panel" id="defaultpanel" data-theme="b">
<div class="panel-content">
<h3>Default panel options</h3>
<p>This panel has all the default options: positioned on the left with the reveal display mode. The panel markup is <em>before</em> the header, content and footer in the source order.</p>
<p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
<a href="#demo-links" data-rel="close" data-role="button" data-theme="c" data-icon="delete" data-inline="true">Close panel</a>
</div><!-- /content wrapper for padding -->
</div><!-- /defaultpanel -->
<!-- Note: all other panels are at the end of the page, scroll down -->
<div data-role="header" data-theme="f" data-position="fixed">
<h1>Panels</h1>
<a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
<a href="../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
</div><!-- /header -->
<div data-role="content">
<h1 id="demo-links">Panels</h1>
<p>Panels are designed to be as flexible as possible to make it easy to create menus, collapsible columns, drawers, inspectors panes and more. </p>
<p><strong>Left</strong> panel examples</p>
<div data-role="controlgroup" data-type="horizontal">
<a href="#leftpanel3" data-role="button">Overlay</a>
<a href="#leftpanel1" data-role="button">Reveal</a>
<a href="#leftpanel2" data-role="button">Push</a>
</div>
<p><strong>Right</strong> panel examples</p>
<div data-role="controlgroup" data-type="horizontal">
<a href="#rightpanel3" data-role="button">Overlay</a>
<a href="#rightpanel1" data-role="button">Reveal</a>
<a href="#rightpanel2" data-role="button">Push</a>
</div>
<h2>Where panel markup goes in a page</h2>
<p>A panel must be a sibling to the header, content and footer elements inside a jQuery Mobile page. You can add the panel markup either <em>before</em> or <em>after</em> these elements, but not in between. A panel cannot be placed outside a page, but this constraint will be removed in a future version.</p>
<p>Here is an example of the panel before the header, content and footer in the source order:</p>
<pre><code>
&lt;div data-role=&quot;page&quot;&gt;
<strong>&lt;div data-role=&quot;panel&quot; id=&quot;mypanel&quot;</strong>&gt;</strong>
&lt;!-- panel content goes here --&gt;
<strong>&lt;/div&gt;&lt;!-- /panel --&gt;</strong>
&lt;!-- header --&gt;
&lt;!-- content --&gt;
&lt;!-- footer --&gt;
&lt;/div&gt;&lt;!-- page --&gt;
</code></pre>
<p>Alternately, it's possible to add the panel markup <em>after</em> the header, content and footer in the source order, just before the end of the page container. Where in the source order you place the panel markup will depend on how you want to page content to read for people experiencing the page in a C-grade device (HTML only) or for a screen reader.</p>
<h2>Panel markup conventions</h2>
<p>A panel consists of a container with a <code>data-role=&quot;panel&quot;</code> attribute and a unique <code>ID</code>. This <code>ID</code> will be referenced by the link or button to open and close the panel. The most basic panel markup looks like this:</p>
<pre><code>
&lt;div <strong>data-role=&quot;panel&quot; id=&quot;leftpanel1&quot;</strong>&gt;
&lt;!-- panel content goes here --&gt;
&lt;/div&gt;
</code></pre>
<p>The <strong>position</strong> of the panel on the screen is set by the <code>data-position</code> attribute. The defaults to <code>left</code>, meaning it will appear from the left edge of the screen. Specify <code>data-position="right"</code> for it to appear from the right edge instead.</p>
<p>The <strong>display mode</strong> of the panel is set by the <code>data-display</code> attribute. The defaults to <code>overlay</code>, meaning the panel will appear to sit under the page and is revealed as the page slides away. Specify <code>data-display="overlay"</code> for it to appear on top of the page contents. A third mode, <code>data-display="push"</code> looks similar to reveal on smaller screens, but at wider widths, the panel slides in and causes the page contents to re-flow to make room so the panel can stay open, so it works like a dismissable column.</p>
<p>The overlay style panel will always be the smoothest and most reliable display mode, especially if combined with fixed toolbars so we recommend you use that mode if possible.</p>
<pre><code>
&lt;div data-role=&quot;panel&quot; id=&quot;leftpanel1&quot; data-position=&quot;left&quot; data-display=&quot;reveal&quot;&gt;
&lt;!-- panel content goes here --&gt;
&lt;/div&gt;
</code></pre>
<h2>Opening a panel</h2>
<p>A panel's visibility is toggled by a link somewhere on the page or by calling the panel's <code>open</code> method directly.</p>
<pre><code>$( "#idofpanel" ).panel( "open" , optionsHash );</code></pre>
<pre><code>
&lt;a href=&quot;#mypanel&quot; <strong>data-rel=&quot;panel&quot;</strong>&gt;Open panel&lt;/a&gt;
</code></pre>
<p>This will create a link that opens our panel with the default options. The defaults place the panel on the left and will push the page over when it opens (reveal mode). </p>
<p>To control a panel from a link, point the <code>href</code> to references the <code>ID</code> of the panel you want to toggle (<code>mypanel</code> in the example above). This instructs the framework to bind the link to the popup. This link will toggle the visibility of the popup so tapping it will open the panel, and tapping it again will close it.</p>
<a href="#defaultpanel" data-role="button" data-inline="true" data-icon="bars">Default panel</a>
<p>When using markup to control panels, you can only have a single panel open at once. Clicking a link to open a panel while one is already open will auto-close the first. This is done to keep the markup-only configuration simple.</p>
<p>That said, it's possible to open multiple panels at once programmatically:</p>
<pre><code>
$( "#idofpanel" )
.panel( "open" , optionsHash )
.then( function( options ){
$( "#idofpanel2" ).panel( "open" , options );
});
</code></pre>
<h2>Closing a panel</h2>
<p>Clicking the link that opened the panel, swiping left or right, or tapping the Esc key will close the panel. </p>
<p>By default, panels can also be closed clicking outside the panel onto the page contents. To prevent this behavior, add the <code>data-dismissible="false"</code> attribute to the panel. Note the since the <code>push</code> mode is designed to have the panel and page to sit side-by-side at wider screen widths, the panel won't be dismissed by clicking on the page on larger screens, regardless of the dismissible settings.</p>
<p>A panel can also be closed by calling the panel's <code>close</code> method directly.</p>
<pre><code>$( "#idofpanel" ).panel( "close" );</code></pre>
<p>It's common to also add a close button inside the panel. To add the link that will close the panel, add the <code>data-rel="close"</code> attribute to tell the framework to close that panel when clicked. It's important to ensure that this link also makes sense if JavaScript isn't available, so we recommend that the <code>href</code> points to the ID of the page where the user should jump to when closing. For example, if the button to open the panel is in the heder bar that has and ID of <code>my-header</code>, the close link in the panel should be:</p>
<pre><code>
&lt;a href=&quot;#my-header&quot; <strong>data-rel=&quot;close&quot;</strong>&gt;Close panel&lt;/a&gt;
</code></pre>
<h2>Panel animations</h2>
<p>Panels will animate if the browser supports 3D transforms, the same criteria for CSS animation support we use for page transitions. Panel animations use <code>translateX</code> CSS transforms to ensure they are hardware accelerated and smooth.</p>
<p>The framework has a feature test to detect if the required CSS properties are supported and will fall back to a simple hide/show if not available. After thorough testing, we decided to not animate panels on less capable platforms because the choppier animations weren't a better experience than a simple hide/show.</p>
<p>The <code>animate</code> option allows you to turn off panel animations for all devices. To turn off animations via markup, add the <code>data-animate="false"</code> attribute to the popup container.</p>
<h2>Panel + fixed positioning</h2>
<p>The panel will be displayed with the <code>position:fixed</code> CSS property so their contents will appear no matter how far down the page you're scrolled. The framework also checks to see if the panel contents will fit within the viewport before applying the fixed positioning because this property would prevent the panel contents from scrolling and using <code>overflow</code> is not well supported enough to use at this time.</p>
<p>If a browser doesn't support fixed positioning or if the panel contents are too long to fit within the viewport, the framework will simply display the panel without fixed positioning. If the user has scrolled down and opens a panel, they may need to scroll up to view the contents. </p>
<p>In general, we recommend that you place the buttons that open the panel at the very top of the screen which is the most common UI pattern for panels. This will avoid the need to scroll and also makes the transitions a bit smoother.</p>
<p>Making panels work with fixed toolbars is fairly complex, but the framework supports this combination. Just be aware that the animation performance will not quite a smooth as inline toolbars and that we must hide the fixed toolbar when the panel opens with the reveal or push display mode and you're scrolled down. We recommend using overlay style panels with fixed headers for best results.</p>
<p>Note that there are issues with fixed positioning within webviews within Android applications (not the browser) that can cause layout issues. We recommend that you turn off the fixed position panel option if deploying to an Android app.</p>
<h2>Styling panels</h2>
<p>By default, panels have very simple styles to let you customize them as needed. Panels are essentially just simple blocks with no padding or margins that sit on either side of the page content. </p>
<p>The framework does need to set a width in order for the CSS animations to work correctly so below 25ems (400px), the panel is set to 80% of the screen width. Above 400px, the panel has a max width of 20ems (320px) since that is a typical panel size. Unfortunately, the styles to set widths on panels are fairly complex but these can be overridden with CSS as needed.</p>
<p>Other than the width and 100% height styles, panels have very little styling on their own. You can set a theme on the panel by add a <code>data-theme</code> to the panel container or add your own classes to style it as needed.</p>
<p>Note that adding padding, borders, or margins directly to the panel container will alter the overall dimensions and could cause the positioning and animation to be affected.</p>
<p>To add padding to a panel, we recommend adding a container inside the panel and applying styles to that to avoid any issues. All the examples on this page follow this pattern.</p>
<h2>Making the panel responsive</h2>
<p>When the push or reveal display is used, a panel pushes the page aside when it opens. Since some of the page is pushed offscreen, the panel is modal and must be closed to interact with the page content again. On larger screens, you may want to have the panel work more like a collapsible column that can be opened and used alongside the page to take better use of the screen real estate. </p>
<p>To make the page work alongside the open panel, it needs to re-flow to a narrower width so it will fit next to the panel. This can be done purely with CSS by adding a left or right margin equal to the panel width (17em) to the page contents to force a re-flow. Second, the invisible layer placed over the page for the click out to dismiss behavior is hidden with CSS so you can click on the page and not close the menu. </p>
<p>Here is an example of these rules wrapped in a media query to only apply this behavior above 35em (560px):</p>
<pre><code>
/* wrap push on wide viewports once open */
@media (min-width: 35em){
.ui-panel-content-wrap.ui-panel-content-wrap-open-complete.ui-panel-content-wrap-display-push,
.ui-panel-content-wrap.ui-panel-content-wrap-open-complete.ui-panel-content-wrap-display-reveal {
margin-right: 17em;
}
.ui-panel-content-wrap.ui-panel-content-wrap-open-complete.ui-panel-content-wrap-display-push.ui-panel-content-wrap-position-right,
.ui-panel-content-wrap.ui-panel-content-wrap-open-complete.ui-panel-content-wrap-display-reveal.ui-panel-content-wrap-position-right {
margin: 0 0 0 17em;
}
.ui-panel-dismiss-display-push {
display: none;
}
}
</code></pre>
<h4>Applying a preset breakpoint</h4>
<p>Included in the widget styles is a breakpoint preset for this behavior that kicks in at 55em (880px). This breakpoint is not applied by default to make it easier for you to write custom breakpoints that work best for your content and design. To apply the breakpoint preset, add the <code>ui-responsive-panel</code> class to the <em>page wrapper</em> (not the panel).</p>
<h2>Options</h2>
<dl>
<dt><code>animate</code> default: true</dt>
<dd>Sets whether the panel will animate when opening and closing. If set to false, the panel will just appear and disappear without animation. This is recommended for fastest performance. Also available via the <code>data-animate</code> attribute on the popup container.</dd>
<dt><code>dismissible</code> default: true</dt>
<dd>Sets whether the panel can be closed by clicking outside onto the page. Also available via the <code>data-dismissible</code> attribute on the link that opens the popup.</dd>
<dt><code>display</code> default: "overlay"</dt>
<dd>The relationship of the panel to the page contents. Can either push the page over ("reveal"), re-flow the content to fit the panel content as a column ("push"), or sit over the content ("overlay"). Also available via the <code>data-display</code> attribute on the link that opens the popup.</dd>
<dt><code>initSelector</code> default: ":jqmData(role='panel')"</dt>
<dd>The role (or and valid jQuery selector) used to trigger auto-initialization of the panel widget.</dd>
<dt><code>position</code> default: "left"</dt>
<dd>The side of the screen the panel appears on. Values can be "left" or "right. Also available via the <code>data-position</code> attribute on the link that opens the popup.</dd>
<dt><code>theme</code> default: null</dt>
<dd>Theme swatch for the panel. Can be any valid swatch letter in your theme (a-z). Also available via the <code>data-theme</code> attribute on the popup container.</dd>
</dl>
<h3>Classes Option</h3>
<p>The <code>classes</code> option define the structural classnames that the plugin uses. This is only configurable via JavaScript because it expects an object literal value.</p>
<dl>
<dt><code>classes.panel</code> default: "ui-panel"</dt>
<dd>Class added to the panel.</dd>
<dt><code>classes.panelOpen</code> default: "ui-panel-open"</dt>
<dd>Class added to the panel when opening. Used for targeting hardware acceleration only during transitions.</dd>
<dt><code>classes.modal</code> default: "ui-panel-dismiss"</dt>
<dd>Class added to the overlay on the page to dismiss the panel when hidden.</dd>
<dt><code>classes.modalOpen</code> default: "ui-panel-dismiss-open"</dt>
<dd>Class added to the invisible overlay over the page when the popup is open. Used to dismiss the panel.</dd>
<dt><code>classes.openComplete</code> default: "ui-panel-open-complete"</dt>
<dd>Class added to the page when the panel animation is complete.</dd>
<dt><code>classes.contentWrap</code> default: "ui-panel-content-wrap"</dt>
<dd>Class added to the wrapper injected around the page contents (header, content, footer), needed for positioning of the panel.</dd>
<dt><code>classes.contentWrapOpen</code> default: "ui-panel-content-wrap-open"</dt>
<dd>Class added to the wrapper injected around the page contents (header, content, footer) when the panel is opening. Used for targeting hardware acceleration only during transitions.</dd>
<dt><code>classes.wrapOpenComplete</code> default: "ui-panel-content-wrap-open-complete"</dt>
<dd>Class added to the page contents wrapper after the open animaation is complete.</dd>
<dt><code>classes.pageBlock</code> default: "ui-panel-page-block"</dt>
<dd>Class added to the page container to suppress scrolling horizontally</dd>
</dl>
<h2>Methods</h2>
<dl>
<dt><code>close</code></dt>
<dd>Closes the panel.
.<pre><code>$( myPanel ).panel( "close" );</code></pre>
</dd>
<dt><code>open</code></dt>
<dd>Opens the panel.
<pre><code>$( myPanel ).panel( "open" );</code></pre>
</dd>
<dt><code>refresh</code></dt>
<dd>Re-enhances any new markup in the panel.
<pre><code>$( myPanel ).panel( "refresh" );</code></pre>
</dd>
<dt><code>toggle</code></dt>
<dd>Toggles the visibility the panel so it will open a closed panel or close and open panel.
<pre><code>$( myPanel ).panel( "toggle" );</code></pre>
</dd>
</dl>
<h2>Events</h2>
<dl>
<dt><code>create</code> Type: panelcreate</dt>
<dd>Triggered when the panel is created.</dd>
</dl>
</div><!-- /content -->
<div data-role="footer" class="footer-docs" data-theme="c">
<p class="jqm-version"></p>
<p>&copy; 2012 jQuery Foundation and other contributors</p>
</div>
<!-- Here are a bunch of panels at the end, just before the close page tag -->
<!-- leftpanel1 -->
<div data-role="panel" id="leftpanel1" data-position="left" data-display="reveal" data-dismissible="true" data-theme="a">
<div class="panel-content">
<h3>Left Panel: Reveal</h3>
<p>This panel is positioned on the left with the reveal display mode. The panel markup is <em>after</em> the header, content and footer in the source order.</p>
<p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
<a href="#demo-links" data-rel="close" data-role="button" data-theme="a" data-icon="delete" data-inline="true">Close panel</a>
</div><!-- /content wrapper for padding -->
</div><!-- /leftpanel1 -->
<!-- leftpanel2 -->
<div data-role="panel" id="leftpanel2" data-position="left" data-display="push" data-dismissible="true" data-theme="a">
<div class="panel-content">
<h3>Left Panel: Push</h3>
<p>This panel is positioned on the left with the push display mode. The panel markup is <em>after</em> the header, content and footer in the source order.</p>
<p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
<a href="#demo-links" data-rel="close" data-role="button" data-theme="a" data-icon="delete" data-inline="true">Close panel</a>
</div><!-- /content wrapper for padding -->
</div><!-- /leftpanel2 -->
<!-- leftpanel3 -->
<div data-role="panel" id="leftpanel3" data-position="left" data-display="overlay" data-dismissible="true" data-theme="a">
<div class="panel-content">
<h3>Left Panel: Overlay</h3>
<p>This panel is positioned on the left with the overlay display mode. The panel markup is <em>after</em> the header, content and footer in the source order.</p>
<p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
<a href="#demo-links" data-rel="close" data-role="button" data-theme="a" data-icon="delete" data-inline="true">Close panel</a>
</div><!-- /content wrapper for padding -->
</div><!-- /leftpanel3 -->
<!-- rightpanel1 -->
<div data-role="panel" id="rightpanel1" data-position="right" data-display="reveal" data-dismissible="true" data-theme="b">
<div class="panel-content">
<h3>Right Panel: Reveal</h3>
<p>This panel is positioned on the right with the reveal display mode. The panel markup is <em>after</em> the header, content and footer in the source order.</p>
<p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
<a href="#demo-links" data-rel="close" data-role="button" data-theme="c" data-icon="delete" data-inline="true">Close panel</a>
</div><!-- /content wrapper for padding -->
</div><!-- /rightpanel1 -->
<!-- rightpanel2 -->
<div data-role="panel" id="rightpanel2" data-position="right" data-display="push" data-dismissible="true" data-theme="b">
<div class="panel-content">
<h3>Right Panel: Push</h3>
<p>This panel is positioned on the right with the push display mode. The panel markup is <em>after</em> the header, content and footer in the source order.</p>
<p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
<a href="#demo-links" data-rel="close" data-role="button" data-theme="c" data-icon="delete" data-inline="true">Close panel</a>
</div><!-- /content wrapper for padding -->
</div><!-- /rightpanel2 -->
<!-- rightpanel3 -->
<div data-role="panel" id="rightpanel3" data-position="right" data-display="overlay" data-dismissible="true" data-theme="b">
<div class="panel-content">
<h3>Right Panel: Overlay</h3>
<p>This panel is positioned on the right with the overlay display mode. The panel markup is <em>after</em> the header, content and footer in the source order.</p>
<p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
<a href="#demo-links" data-rel="close" data-role="button" data-theme="c" data-icon="delete" data-inline="true">Close panel</a>
</div><!-- /content wrapper for padding -->
</div><!-- /rightpanel3 -->
</div><!-- /page -->
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.