DIV CSS 佈局教程網

jQuery Mobile 重點整理:從 data-role 到頁面過場動畫
編輯:JQuery特效代碼     

一、jQuery Mobile 與 jQuery 的差異

jQuery Mobile 是一個針對觸控最佳化的行動框架,用於打造行動版 Web 應用程式,它建構在 jQuery 之上,適用於主流智慧型手機與平板。官網還提供了頁面設計工具與主題設計工具,其 JS 外掛也涵蓋換頁、事件等多項功能。

原生 App 的開發語言各不相同:Android 與 BlackBerry 多用 Java、iOS 用 Objective-C、Windows Phone 則用 C# 與 .NET。jQuery Mobile 的價值在於只需 HTML、CSS 與 JavaScript 這些各平台通用的標準技術,就能一次搞定。

二、data-role 屬性

  • data-role="page":顯示於瀏覽器中的頁面
  • data-role="header":建立頁面上方的工具列(常用於標題與搜尋按鈕)
  • data-role="content":定義頁面內容,如文字、圖片、表單、按鈕等
  • data-role="footer":建立頁面底部的工具列

在這些容器中可加入任意 HTML 元素——段落、圖片、標題、清單等。HTML5 的 data-* 屬性正是用來透過 jQuery Mobile 為行動裝置打造「對觸控友善」的互動外觀。

三、對話框

若要讓使用者點擊(輕觸)連結時彈出對話框(用來顯示訊息或要求輸入的視窗),只要為該連結加上 data-rel="dialog" 即可。

<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> <script src="https://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>歡迎光臨</h1> </div> hello <br/> <div date-role="content"> <a href="#pagetwo" data-rel="dialog">以對話框的形式跳轉到頁面2</a> </div> <div data-role="footer"> <h1> 尾部 </h1> </div> </div> <div data-role="page" id="pagetwo"> <div data-role="header"> <h1>頁面2標題欄</h1> </div> world <br/> <div date-role="content"> <a href="#pageone">跳轉到頁面1</a> </div> <div data-role="footer"> <h1>頁面2 尾部 </h1> </div> </div> </body> </html>

四、頁面過場

jQuery Mobile 內建多種 CSS 過場效果,讓你能選擇頁面的開啟方式,但需瀏覽器支援 CSS3 3D 轉換。預設為 fade;若想反向播放,可加上 data-direction="reverse"。可選效果包含:fade(淡入淡出)、flip(翻轉)、flow(拋出)、pop(彈出)、slide(滑動)、slidefade(滑動並淡入)、slideup(由下往上)、slidedown(由上往下)、turn(轉向)、none(無過場)。

 <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> <script src="https://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>歡迎光臨</h1> </div> hello <div date-role="content"> <a href="#pagetwo" data-transition="slide">跳轉到頁面2</a> </div> <div data-role="footer"> <h1> 尾部 </h1> </div> </div> <div data-role="page" id="pagetwo"> <div data-role="header"> <h1>頁面2標題欄</h1> </div> world <br/> <div date-role="content"> <a href="#pageone" data-transition="slide" data-direction="reverse">跳轉到頁面1</a> </div> <div data-role="footer"> <h1>頁面2 尾部 </h1> </div> </div> </body> </html>

五、按鈕

jQuery Mobile 可透過 data-role="button" 將元素樣式化為按鈕,並用 data-inline、data-corners、data-shadow、data-mini 等屬性控制行內顯示、圓角、陰影與尺寸。

 <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> <script src="https://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="https://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> <script src="demo.js"></script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>按鈕</h1> </div> <div data-role="content" data-inline="true"> <button>按鈕</button> </div> <div data-role="content"> <input type="button" value="button" data-inline="true"></input> </div> <div data-role="content"> <a href="#" data-role="button" data-corner="true" data-inline="true">button</a> <a href="#" data-role="button" data-corner="false" data-inline="true">button</a> </div> <div data-role="controlgroup" data-type="horizontal"> <a href="#pagetwo" data-role="button" id="button1">button</a> <a href="#" data-role="button" >button</a> </div> <div data-role="content"> <a href="#" data-role="button">按鈕 1</a> <a href="#" data-role="button" data-corners="false">按鈕 2</a> </div> <div data-role="footer"> <h1>頁腳文本</h1> </div> </div> <div data-role="page" id="pagetwo"> <div data-role="header">header</div> <div data-role="content"> <a href="#" data-role="button" data-rel="back" >後退</a> </div> <div data-role="footer">footer</div> </div> </body> </html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved