Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery Mobile Popups

jQuery Mobile Popups

A popup is a very popular dialog that can be displayed over the page.

A popup can be used to display a piece of text, an image, a map, or other content.

To create a popup, use the and

element. Add the data-rel="popup" attribute to the element, and the data-role="popup" attribute to the
element. Then we assign an id to the
, and set the 's href value to the
specified id.
The content inside is the content displayed in the popup.

Note:

Try it »

If you need to add inner and outer padding to the popup, you can add the "ui-content" class in the

:

Example

class="ui-content"

Try it »


Closing a popup

By default, clicking outside the popup area or pressing the "Esc" key will close the popup. If you don't want clicking outside the popup to close it, you can add the data-dismissible="false" attribute (not recommended). You can also add a close button on the popup, using the data-rel="back" attribute on the button, and control the button's position with styles.

Description Example
Close button on the right Try it
Close button on the left Try it
Using the data-dismissible attribute Try it

Positioning popups

By default, the popup is displayed directly above the clicked element. To control the popup's position, you can use the data-position-to attribute on the click link that opens the popup.

Three ways to control popup position:

Attribute values Description
data-position-to="window" Popup centered in the window
data-position-to="#myId" Popup displayed over the specified #id element
data-position-to="origin" Default. Popup displayed over the clicked element.

Example

data-position-to="window"

Window

data-position-to="#demo">

id="demo"

data-position-to="origin"

Origin

Try it »


Transition

By default, popups have no transition effect. If you need one you can add a transition effect with the data-transition="value" attribute (jQuery Mobile Transitions):

All transition effect examples

data-transition="fade"

Fade

Try it »


Popup directional small border

If you need to add a directional small border to the popup, you can use the data-arrow attribute and specify the value "l" (left), "t" (top), "r" (right) or "b" (bottom):

Example

Open modal

data-arrow="l"

 

The direction of the left border.

Try it »


Popup dialog

You can make a popup into a standard dialog (header, content, and footer markup):

Example

Open dialog popup

 

Header text..

 

Some text..

Some links..

 

Footer text..

Try it »


Image popup

You can display an image in a popup:

Example

Runoob

  Runoob

Try it »


Popup background overlay

You can use the data-overlay-theme attribute to add a background color behind the popup.

By default the overlay background color is transparent. Use data-overlay-theme="a" to add a light background, and data-overlay-theme="b" to add a dark overlay background:

Example

Show Popup

data-overlay-theme="b"

 

There is a dark background behind me.

Try it »

Image popups often use a background overlay:

Example

Runoob

data-overlay-theme="b"

  Runoob

Try it »

Note: In the next chapter, you will learn how to use forms in popups.