jQuery Mobile 使用 HTML5 & CSS3 最小的脚本来布局网页。

编写代码要注意最外层div需要添加data-role="page" ,标题需要添加data-role="header",内容需要添加data-role="content",底部需要添加data-role="footer"。

代码:

----------------------------------------------------------

<div data-role="page" >
  <div data-role="header">
    <h1>页面标题</h1>
  </div>

<div data-role="content">
    <p>页面内容</p>
  </div>

<div data-role="footer">
    <h1>页面底部内容</h1>
  </div>
</div>

----------------------------------------------------------

jQuery Mobile 页面切换效果

1. 页面切换效果可被应用于任何使用 data-transition 属性的链接或表单提交

代码:

<a href="#div2" data-transition="slide">切换到div2</a>

<a href="#div1" data-transition="slide">切换到div1</a>

data-transition的参数:

fade:默认淡入到下一页;flip:从后向前翻转到下一页;flow:前一页缩小向左抛出到下一页;pop:弹出进入下一页; slide:从右到左滑动到下一页

slidefade:从右到左滑动并淡入到下一页;slideup:从下到上滑动到下一页;slidedown:从上到下滑动到下一页;turn:翻到下一页;none:去除效果。

2. data-transition的所有效果都支持退后功能需添加data-direction="reverse"

代码:

<a href="#div2" data-transition="flow">切换到div2</a>

<a href="#div1" data-transition="flow"  data-direction="reverse">切换到div1</a>

jQuery Mobile 按钮

1. 在 jQuery Mobile 中,按钮可通过三种方式创建:

  • 使用 <button> 元素
  • 使用<input type="button" value="按钮"> 元素
  • 使用带有 <a href="#" data-role="button">按钮</a> 的 <a> 元素

在什么场景用那种按钮:

data-role="button" 用于页面之间的链接 input 和button用于表单提交

代码:

<a href="#div2" data-role="button">访问第二个页面</a>

<a href="#div1" data-role="button">访问第二个页面</a>

<div data-role="page"  id="div1">
  <div data-role="header">
    <h1>页面标题</h1>
  </div>

<div data-role="content">
    <p><a href="#div2" data-role="button">访问第二个页面</a></p>
  </div>

<div data-role="footer">
    <h1>页面底部内容</h1>
  </div>
</div>

<div data-role="page"  id="div2">
  <div data-role="header">
    <h1>页面标题</h1>
  </div>

<div data-role="content">
    <p><a href="#div1" data-role="button">访问第二个页面</a></p>
  </div>

<div data-role="footer">
    <h1>页面底部内容</h1>
  </div>
</div>

2. 按钮默认情况下都是占满屏幕宽度,所以提供了data-inline="true"让按钮的宽度和字一样宽

<a href="#pagetwo" data-role="button" data-inline="true">按钮宽度和我一样</a>

3. jqmobile组合按钮,组合顾名思义是几个按钮拼接在一起,那么就有两种情况,一种是一个按钮占一行(默认),一种是几个按钮占一行;所以提供data-role="controlgroup" 属性和 data-type="horizontal|vertical"对按钮布局。

代码:

<div data-role="page" id="pageone">
  <div data-role="header">
  <h1>组合按钮</h1>
  </div>

<div data-role="content">
    <div data-role="controlgroup" data-type="horizontal">
    <p>水平组合按钮:</p>
    <a href="#" data-role="button">按钮 1</a>
    <a href="#" data-role="button">按钮 2</a>
    <a href="#" data-role="button">按钮 3</a>
    </div><br>
    
    <div data-role="controlgroup" data-type="vertical">
    <p>垂直组合按钮 (默认):</p>
    <a href="#" data-role="button">按钮 1</a>
    <a href="#" data-role="button">按钮 2</a>
    <a href="#" data-role="button">按钮 3</a>
    </div>
  </div>

<div data-role="footer">
  <h1>底部文本</h1>
  </div>
</div>

4. jqmobile后退按钮需要添加 data-rel="back"。

代码:

<a href="#" data-role="button" data-rel="back">返回</a>

5. 更多用于按钮的data-*属性

data-corners="true/false"   是否让按钮圆角

data-mini="true/false"        规定按钮是否最小

data-shadow="/true/false"  按钮是否有阴影

6. jqmobile按钮图标 添加 data-icon="”

data-icon="arrow-l"  左箭头

data-icon="arrow-r" 右箭头

data-icon="delete" 删除

data-icon="info" 信息

data-icon="home" 首页

data-icon="back" 后退

data-icon="search" 搜索

data-icon="grid" 网格

代码:

<a href="#anylink" data-role="button" data-icon="arrow-l">Search</a>

7. 图标定位 添加data-iconpos=""/顶部(top)、右侧(right)、底部(bottom)、左侧(left)。

代码:

<a href="#link" data-role="button" data-icon="search" data-iconpos="top">顶部</a>
<a href="#link" data-role="button" data-icon="search" data-iconpos="right">右侧</a>
<a href="#link" data-role="button" data-icon="search" data-iconpos="bottom">底部</a>
<a href="#link" data-role="button" data-icon="search" data-iconpos="left">左侧</a>

8. 只显示图标添加data-iconpos="notext"

代码:

<a href="#link" data-role="button" data-icon="search" data-iconpos="notext">搜索</a>

jQuery Mobile 工具栏

下面的代码,将添加一个按钮到头部标题文本的左侧,添加一个按钮到头部标题文本的右侧

<div data-role="header">
<a href="#" data-role="button">首页</a>
<h1>欢迎来到我的主页</h1>
<a href="#" data-role="button">搜索</a>
</div>

下面的代码,将添加一个按钮到头部标题文本的左侧:

<div data-role="header">
<a href="#" data-role="button">首页</a>
<h1>欢迎来到我的主页</h1>
</div>

如果您把按钮链接放置在 <h1> 元素之后,将无法显示右侧的文本。要添加一个按钮到头部标题的右侧,请指定 class 为 "ui-btn-right":

<div data-role="header">
<h1>欢迎来到我的主页</h1>
<a href="#" data-role="button" class="ui-btn-right">搜索</a>
</div>

皓轩的jquery mobile之路(二)的更多相关文章

  1. jQuery插件之路(二)——轮播

    还记得以前刚接触前端的时候,浏览各大网站,很多都少不了的有个轮播的效果,那个时候自己是一个彻彻底底的小白,想着这些图片滚动起来还真是有意思,是什么让这些图片在一个方向上连续的滚动呢.后来慢慢的接触多了 ...

  2. Jquery学习之路(二) 实现table样式的设定

    上一篇jquery实现checkbox的全选,得到了一些朋友的建议,其中插件的定义我的确不太清楚,也闹了个笑话,有些朋友建议我去看<锋利的Jquery>,说实话正在看了.由于正在学习中,我 ...

  3. 18个jQuery Mobile开发贴士和教程

    jQuery Mobile 是 jQuery 在手机上和平板设备上的版本.jQuery Mobile 不仅会给主流移动平台带来jQuery核心库,而且会发布一个完整统一的jQuery移动UI框架.支持 ...

  4. 使用 jQuery Mobile 与 HTML5 开发 Web App 系列文章目录

    使用 jQuery Mobile 与 HTML5 开发 Web App 系列文章目录 时间:2012年9月20日 分类:JavaScript 标签:HTML5‚ jQuery Mobile‚ Web ...

  5. (二)Jquery Mobile介绍以及Jquery Mobile页面与对话框

    Jquery Mobile介绍以及Jquery Mobile页面与对话框  一. Adobe Dreamweaver CS6 环境 最新版本的cs6会支持JM的使用,有自动提示功能,很强大.安装说明地 ...

  6. 小强的HTML5移动开发之路(47)——jquery mobile基本的页面框架

    一.单容器页面结构 <!DOCTYPE html> <html> <head> <title>Jquery mobile 基本页面框架</titl ...

  7. 小强的HTML5移动开发之路(23)—— jQuery Mobile入门

    一.下载jQuery Mobile 下载地址:http://jquerymobile.com/ 点击Download 下载如下zip包 下载成功后如下图 解压目录如图: 点击index.html进入d ...

  8. jQuery Mobile学习日记(二)

    首先依HTML5方式加载,DOCTYPE表示格式为HTML5:主要适用于iPhone.Android等,viewport表示适用于移动终端的适中显示,initial-scale缩放比例在1.0~1.3 ...

  9. jquery Mobile应用第2课《构建跨平台APP:jQuery Mobile移动应用实战》连载二(简单的QWER键盘)

    在jQuery Mobile的布局中,控件大多都是单独占据页面中的一行,按钮自然也不例外,但是仍然有一些方法能够让多个按钮组成一行,比如说在范例6-5中就利用按钮分组的方法使4个按钮并列在一行中,如图 ...

随机推荐

  1. wps制作目录

    01 设置标题为.标题1.标题2,标题302 引用--插入目录03 配置文档结构图.查看--可快速回到目录

  2. MVC中用 BundleCollection 压缩CSS时图片路径问题

    MVC中有个专门提供JS和CSS压缩的类,BundleCollection,其实这个类也可以在asp.net中用, 关于BundleCollection类的详细推荐个地址:http://www.cnb ...

  3. hdu 1394 Minimum Inversion Number(这道题改日我要用线段树再做一次哟~)

    Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of ...

  4. permutation求全排列

    include <iostream> #include <string> using namespace std; void swap(char &c1, char & ...

  5. webapp前端开发软键盘与position:fixed为我们带来的不便

    前提:我们考虑兼容的环境为android和ios两种智能手机 兼容环境测试结果显示android的表现明显好于ios,ios手机在软键盘呼起收起时存在着很严重的兼容性问题 场景展示: 页面正常状态 软 ...

  6. JPG、PNG和GIF图片的基本原理及优化方法

    一提到图片,我们就不得不从位图开始说起,位图图像(bitmap),也称为点阵图像或绘制图像,是由称作像素(图片元素)的单个点组成的.这些点可以进行不同的排列和染色以构成一副图片.当放大位图时,可以看见 ...

  7. JavaScript焦点事件、鼠标事件和滚轮事件使用详解

    网址:http://www.jb51.net/article/78094.htm

  8. 在Linux服务器上增加硬盘没那么简单【转】

    运维案例:HP服务器,LINUX系统在保障数据的前提下扩展/home分区 部门需求:研发部门提出需要在现有的服务器上扩容磁盘空间,以满足开发环境的磁盘需求.现有空间1.6T需要增加到2T. 需求调查分 ...

  9. 戏说云计算之PaaS,IaaS,SaaS【转载】

    最近我们聊到“CRM系统PAAS化”,有些可能就不了解,到底什么是PAAS.云计算还有IaaS,SaaS概念,这三者之间有什么区别?今天智云通CRM系统小编用通俗易懂的例子跟大家分享Paas,IaaS ...

  10. 前端 MVC 变形记

    背景: MVC是一种架构设计模式,它通过关注点分离鼓励改进应用程序组织.在过去,MVC被大量用于构建桌面和服务器端应用程序,如今Web应用程序的开 发已经越来越向传统应用软件开发靠拢,Web和应用之间 ...