顯示具有 jQuery Mobile 標籤的文章。 顯示所有文章
顯示具有 jQuery Mobile 標籤的文章。 顯示所有文章

2012年8月11日 星期六

[jQuery Mobile] Multi-page


簡介


多網頁架構是由兩個以上的 <div data-role="page"> ... </div> 組成。每個 <div> 元件的內容設計如同單一網頁 ( Single-page )的撰寫架構,包含:標頭  <div data-role="header"> ... </div>、內容    <div data-role="content"> ... </div> 與頁尾   <div data-role="footer"> ... <div>。

範例:Multi-page


點選 JSFIDDLE 的 HTML,<body> 標籤內介紹並參考以下介紹:


  1. 使用兩個 <div> 元件,元件 ID 分別為 FirstPage 與 SecondPage ,以下分別稱為First 和Second 網頁。
  2. First  網頁內的網頁內容標籤 <div data-role="content"> ... </div>  說明「點選網頁的 page 2 連結,切換至 Second 網頁」。請選擇 JSFIDDLE 的 Result 測試。
  3. Second  網頁內的網頁內容標籤 <div data-role="content"> ... </div>  說明「點選網頁的 page 1 連結,切換至 First網頁」。請選擇 JSFIDDLE 的 Result 測試。

   

重點摘錄


  • A single HTML document can contain multiple 'pages' that are loaded together by stacking multiple divs with a data-role of "page". 
  • Since we are using the hash to track navigation history for all the Ajax 'pages', it's not currently possible to deep link to an anchor (index.html#foo) on a page in jQuery Mobile, because the framework will look for a 'page' with an ID of #foo instead of the native behavior of scrolling to the content with that ID.
  • The id attribute of all your elements must be not only unique on a given page, but also unique across the pages in a site. This is because jQuery Mobile's single-page navigation model allows many different "pages" to be present in the DOM at the same time. This also applies when using a multi-page template, since all "pages" on the template are loaded at once
  • We strongly recommend building your site or app as a series of separate pages like this because it's cleaner, more lightweight and works better without JavaScript.


參考資料

2012年8月8日 星期三

[jQuery Mobile] Hello World

練習環境


練習 jQuery Mobile 建議使用 jsfiddle ,關於jsfiddle 介紹請點我。
進入 jsfiddle 後,先設定 framework ,選擇 jQuery 和勾選 jQuery Mobile ,如下圖:


















接下來,新增資源,設定jQuery Mobile 所需的 CSS,
將 http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css 貼至欄位中,按下 + 號,如下圖:










範例:Hello World


點選 JSFIDDLE 的 HTML,<body> 標籤內介紹基本的撰寫架構。
  1. 網頁內容用 <div data-role="page"> ... </div> 包覆。
  2. 基本網頁內容包含:   
  • 標頭  <div data-role="header"> ... </div>
  • 內容    <div data-role="content"> ... </div>
  • 頁尾   <div data-role="footer"> ... <div> 
點選 Result ,查看執行結果。



重點摘錄


  • Each link or form from here will pull a new page in via Ajax to support the animated page transitions.
  • The page, header, content, and footer data-role elements are mostly helpful for providing some basic formatting and structure.

參考資料