mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +00:00
137 lines
No EOL
9.7 KiB
HTML
Executable file
137 lines
No EOL
9.7 KiB
HTML
Executable file
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>jQuery Mobile Docs - Intro</title>
|
|
<link rel="stylesheet" href="../css/all" />
|
|
<script type="text/javascript" src="../js/all"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<div data-role="page">
|
|
|
|
<div data-role="header">
|
|
<h1>Page structure</h1>
|
|
</div><!-- /header -->
|
|
|
|
<div data-role="content" class="ui-body">
|
|
|
|
<p>Following HTML markup conventions is essential to this approach because markup is the primary mechanism used to configure the mobile experience in jQuery Mobile. Validate your code and always avoid the use of inline styles or inline JavaScript event handlers to ensure the best results.</p>
|
|
|
|
<h2>Mobile page structure</h2>
|
|
|
|
<p>A jQuery Mobile site starts with an HTML5 'doctype'. In the 'head', references to jQuery, jQuery Mobile and the mobile theme CSS are all required to start things off:</p>
|
|
|
|
<div class="highlight">
|
|
<pre><span class="cp"><!DOCTYPE html></span>
|
|
<span class="nt"><html></span>
|
|
<span class="nt"><head></span>
|
|
<span class="nt"><meta</span> <span class="na">charset=</span><span class="s">"UTF-8"</span> <span class="nt">/></span>
|
|
<span class="nt"><title></span>Page Title<span class="nt"></title></span>
|
|
<span class="nt"><link</span> <span class="na">rel=</span><span class="s">"stylesheet"</span> <span class="na">type=</span><span class="s">"text/css"</span> <span class="na">href=</span><span class="s">"..."</span> <span class="nt">/></span>
|
|
<span class="nt"><script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"jquery-min.js"</span><span class="nt">></script></span>
|
|
<span class="nt"><script </span><span class="na">type=</span><span class="s">"text/javascript"</span> <span class="na">src=</span><span class="s">"jquery-mobile-min.js"</span><span class="nt">></script></span>
|
|
<span class="nt"></head></span>
|
|
<span class="nt"><body></span>
|
|
...
|
|
<span class="nt"></body></span>
|
|
<span class="nt"></html></span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>Inside the <code><body></code> tag, each view or "page" on the mobile device is identified with an element (usually a <code>div</code>) with the <code>data-role="page"</code> attribute:</p>
|
|
|
|
<div class="highlight">
|
|
<pre><span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"page"</span><span class="nt">></span>
|
|
...
|
|
<span class="nt"></div></span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>Within the "page" container, any valid HTML markup can be used, but for typical pages in jQuery Mobile, the immediate children of a "page" are divs with data-roles of <code>"header"</code>, <code>"content"</code>, and <code>"footer"</code>.</p>
|
|
|
|
<div class="highlight">
|
|
<pre><span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"page"</span><span class="nt">></span>
|
|
<span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"header"</span><span class="nt">></span>...<span class="nt"></div></span>
|
|
<span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"content"</span><span class="nt">></span>...<span class="nt"></div></span>
|
|
<span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"footer"</span><span class="nt">></span>...<span class="nt"></div></span>
|
|
<span class="nt"></div></span>
|
|
</pre>
|
|
</div>
|
|
|
|
<h2>External page linking</h2>
|
|
|
|
<p>Most sites or applications will consist of multiple HTML pages that are linked. As long as each page in the standard jQuery Mobile structure, to link between them, simply <code>data-role</code> of <code>"page"</code>, multiple 'pages' can be assembled and loaded together. This allows you to build a small site or application within a single document and jQuery Mobile will simply display the first 'page' it finds in the source order when the page loads.</p>
|
|
|
|
<p>jQuery Mobile automates the process of building AJAX powered site and applications. By default, when you click on link that points to an external page (ex. products.html), the framework will parse the link's <code>href</code> to formulate an AJAX request (Hijax) and displays the loading spinner.</p>
|
|
|
|
<p>If the AJAX request is successful, the new page content is added to the DOM, the <code>mobilize()</code> function runs, then the new page is animated into view with a <a href="transitions.html">page transition</a>. </p>
|
|
|
|
<h2>Local, internal linked "pages"</h2>
|
|
|
|
<p>A single HTML document can contain either a single 'page' or, by stacking multiple divs with a <code>data-role</code> of <code>"page"</code>, multiple 'pages' can be assembled and loaded together. This allows you to build a small site or application within a single document and jQuery Mobile will simply display the first 'page' it finds in the source order when the page loads.</p>
|
|
|
|
<p>If a link points to an anchor (#foo), the framework will looks for a page with that ID. If it finds a page in the HTML document, it will transition the new page into view.</p>
|
|
|
|
<p>Here is an example of a 2 "page" site built with two jQuery Mobile divs navigated by linking to an ID placed on each page wrapper. Note that the IDs on the page wrappers are only needed to support the internal page linking and are optional if each page is a separate HTML document.</p>
|
|
|
|
<div class="highlight">
|
|
<pre><span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"page"</span> <span class="na">id=</span><span class="s">"foo"</span><span class="nt">></span>
|
|
<span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"content"</span><span class="nt">></span>
|
|
I'm the "foo" page. Since I'm the first page
|
|
in the source order, I will be displayed onLoad.
|
|
<span class="nt"><a</span> <span class="na">href=</span><span class="s">"#bar"</span><span class="nt">></span>Visit the bar "page"<span class="nt"></a></span>
|
|
<span class="nt"></div><!-- /content --></span>
|
|
<span class="nt"></div><!-- /foo page --></span>
|
|
|
|
<span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"page"</span> <span class="na">id=</span><span class="s">"bar"</span><span class="nt">></span>
|
|
<span class="nt"><div</span> <span class="na">data-role=</span><span class="s">"content"</span><span class="nt">></span>
|
|
I'm the "bar" page. I will be shown only if the
|
|
anchor link on the <span class="nt"><a</span> <span class="na">href=</span><span class="s">"#foo"</span><span class="nt">></span>foo<span class="nt"></a></span>
|
|
page is clicked.
|
|
<span class="nt"></div></span><span class="nt"><!-- /content --></span>
|
|
<span class="nt"></div><!-- /bar page --></span>
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<p>You can seamlessly navigate between local, internal "pages" and external pages in jQuery UI. Both will look the same to the end user except that external pages will display the AJAX spinner while loading. In either situation, jQuery Mobile updates the page's URL hash to enable Back button support, deep-linking and bookmarking. </p>
|
|
|
|
<h2>Page transitions</h2>
|
|
|
|
<p>The jQuery Mobile framework includes a set of CSS-based transitions that can be applied to any object or page change event. By default, when navigating to a new page, the framework applies the right to left slide transition effect. When via the Back button, the slide transition direction is reversed.</p>
|
|
<p>Learn more about the technical details of the <a href="/jquery/jquery-mobile/wiki/Page-Navigation-Model">Page-Navigation-Model</a>.</p>
|
|
|
|
<p>To set a custom transition effect, add the <code>data-transition</code> attribute to the link. Possible values include: </p>
|
|
|
|
<pre><code>
|
|
<a href="index.html" data-transition="pop">I'll pop</a>
|
|
</pre></code>
|
|
<a href="../_transitions-destination.html" data-role="button" data-inline="true" data-transition="slide">slide</a>
|
|
<a href="../_transitions-destination.html" data-role="button" data-inline="true" data-transition="slideup">slideup</a>
|
|
<a href="../_transitions-destination.html" data-role="button" data-inline="true" data-transition="slidedown">slidedown</a>
|
|
<a href="../_transitions-destination.html" data-role="button" data-inline="true" data-transition="pop">pop</a>
|
|
<a href="../_transitions-destination.html" data-role="button" data-inline="true" data-transition="flip">flip</a>
|
|
<a href="../_transitions-destination.html" data-role="button" data-inline="true" data-transition="fade">fade</a>
|
|
|
|
<h2>Dialogs</h2>
|
|
|
|
<p>Any page can be presented as a dialog by adding the </a>data-rel="dialog"</code> attribute to the page you're linking to. The framework will add styles to make the page look like a modal dialog by adding rounded corners and margins around the page along with a dark background behind the "dialog".</p>
|
|
|
|
<p>The dialog will still open with the standard slide transition so to make it feel more dialog-like, we recommend adding a transition of pop, slideup or flip on the link too.</p>
|
|
|
|
<pre><code>
|
|
<a href="../_dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Open dialog: pop</a>
|
|
</pre></code>
|
|
|
|
<a href="../_dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="pop">Open dialog: pop</a>
|
|
<a href="../_dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="slideup">Open dialog: slideup</a>
|
|
<a href="../_dialog.html" data-role="button" data-inline="true" data-rel="dialog" data-transition="flip">Open dialog: flip</a>
|
|
|
|
|
|
|
|
|
|
</div><!-- /content -->
|
|
</div><!-- /page -->
|
|
|
|
</body>
|
|
</html> |