jQuery Mobile学习笔记(三)——UI组件

这一章,详细学习一下常用的JM组件。组件基本上可以分为一下几类:

  • 工具栏组件
  • 格式化组件
  • 按钮组件
  • 列表组件
  • 表单组件
1.工具栏组件(页头、页脚):
定位:
内联模式——页面长度超过可见高度时,页脚将被隐藏,同时页头只在滚动条在顶部时才可见(默认模式)。
标准固定模式——data-position=“fixed”,用户滚动页面内容时,工具栏会自动隐藏,滚动完成时,固定工具栏会再次在顶部或底部对应的位置出现。
全屏固定模式——data-position=”fixed”/data-fullscreen=”true”在点击屏幕时才出现的隐藏的固定工具栏,再次点击时,又会消失。

=================================================


 
header中一个a元素相当于一个按钮,一个a元素,位于标题左侧,两个a元素,一个左一个右。可以使用class=”ui-btn-right”/class=”ui-btn-left”来强制制定按钮位置。
data-icon表示应用图标 –>
   log out
   


   Settings
标签,在里面添加内容即可–>
 


 

 



 

Refresh
    Filter
    Search
    New Item

 


===============================
导航栏:data-role=”navbar”,一组链接组成的一系列互斥选项。通常放在页脚。导航栏的元素控制在6个一下,以便让它们全部显示为一行。
仿微信样式:
[html] view plain copy
print ?
  1. <div data-role=“header” data-position=“fixed”>  
  2.   <h1>Homeh1>  
  3.   <div data-role=“navbar”>  
  4.     <ul>  
  5.       <li><a href=“#index” data-icon=“home”>Homea>  
  6.       <li><a href=“#contacts” data-icon=“search”>Contactsa>  
  7.       <li><a href=“#events” data-icon=“info”>Eventsa>  
  8.       <li><a href=“#news” data-icon=“grid”>Newsa>  
  9.     ul>  
  10.   div>  
  11. div>  
被选中的元素:class=”ui-btn-active”
[html] view plain copy
print ?
  1. <div data-role=“footer” data-position=“fixed”>  
  2.   <div data-role=“navbar”>  
  3.     <ul>  
  4.       <li><a href=“#index” <span style=“background-color: rgb(51, 204, 255);”>class=“ui-btn-active”span>>Homea>  
  5.       <li><a href=“#contacts”>Contactsa>  
  6.       <li><a href=“#events”>Eventsa>  
  7.       <li><a href=“#news”>Newsa>  
  8.     ul>  
  9.   div>  
  10. div>  
固定页脚,不会更新(data-role=”footer“中data-id相同):
[html] view plain copy
print ?
  1. >  
  2. <html>  
  3.  <head>  
  4.        
  5.  head>  
  6.   
  7.  <body>  
  8.     <div data-role=“page” id=“home”>  
  9.   
  10.     <div data-role=“header”>  
  11.             <h1>Homeh1>  
  12.   
  13.     div>  
  14.   
  15.     <div data-role=“content”>  
  16.             <p>This is content for the homep>  
  17.     div>  
  18.   
  19.     <div data-role=“footer”<span style=“background-color: rgb(255, 255, 255);”> span><span style=“background-color: rgb(51, 204, 255);”>data-id=“main”span> position=“fixed”>  
  20.       <div data-role=“navbar”>  
  21.        <ul>  
  22.          <li><a data-icon=“home” <span style=“background-color: rgb(51, 204, 255);”>class=“ui-btn-active ui-state-persist”span>>Homea>li>  
  23.          <li><a href=“#help” data-icon=“alert”>Helpa>li>  
  24.        ul>  
  25.       div>  
  26.      div>  
  27.   
  28.  div>  
  29.   
  30.   
  31.  <div data-role=“page” id=“help”>  
  32.   
  33.     <div data-role=“header”>  
  34.             <h1>Helph1>  
  35.      div>  
  36.   
  37.     <div data-role=“content”>  
  38.             <p>This is content for Helpp>  
  39.      div>  
  40.   
  41.     <div data-role=“footer” <span style=“background-color: rgb(51, 204, 255);”>data-id=“main”span>  position=“fixed”>  
  42.       <div data-role=“navbar”>  
  43.        <ul>  
  44.          <li><a href=“#home” data-icon=“home”>Homea>li>  
  45.          <li><a data-icon=“alert” <span style=“background-color: rgb(51, 204, 255);”>class=“ui-btn-active ui-state-persist”span>>Helpa>li>  
  46.        ul>  
  47.       div>  
  48.      div>  
  49.   
  50.     div>  
  51.   
  52.  body>  
  53.  html>  


 
     
 

 
    

Home

This is content for the home

data-id="main" position="fixed">

Help

This is content for Help

data-id="main" position="fixed">
2.格式化组件
2.1可折叠内容data-role=”collapsible”
[html] view plain copy
print ?
  1. <div data-role=“content”>  
  2.   
  3. <div data-role=“collapsible”>  
  4.   <h2>History of Romeh2>  
  5.   <p>There is archaeological evidence of human occupation of the Rome area from at   
  6.      least 14,000 years, but the dense layer of much younger debris obscures   
  7.      Palaeolithic and Neolithic sites.[11] Evidence of stone tools, pottery and   
  8.      stone weapons attest to at least 10,000 years of human presence.  
  9.   p>  
  10. div>  
  11.   
  12. <div data-role=“collapsible” data-collapsed=“true”>   
  13.   <h2>Government of Romeh2>  
  14.   <p>Rome constitutes one of Italy’s 8,101 communes, and is the largest both in terms   
  15.      of land area and population. It is governed by a mayor, currently Gianni Alemanno,   
  16.      and a city council.  
  17.   p>  
  18. div>  
  19.   
  20. div>  

History of Rome

There is archaeological evidence of human occupation of the Rome area from at least 14,000 years, but the dense layer of much younger debris obscures Palaeolithic and Neolithic sites.[11] Evidence of stone tools, pottery and stone weapons attest to at least 10,000 years of human presence.

Government of Rome

Rome constitutes one of Italy's 8,101 communes, and is the largest both in terms of land area and population. It is governed by a mayor, currently Gianni Alemanno, and a city council.

嵌套可折叠内容:
[html] view plain copy
print ?
  1. <div data-role=“content”>  
  2.   <div data-role=“collapsible”>  
  3.      <h2>Romeh2>  
  4.      <div data-role=“collapsible”>  
  5.        <h3>Historyh3>  
  6.        <p>There is archaeological evidence of human occupation of the Rome area from   
  7.           at least 14,000 years, but the dense layer of much younger debris obscures   
  8.           Palaeolithic and Neolithic sites.[11] Evidence of stone tools, pottery and   
  9.           stone weapons attest to at least 10,000 years of human presence. p>  
  10.      div>  
  11.      <div data-role=“collapsible” data-collapsed=“true”>  
  12.        <h3>Governmenth3>  
  13.        <p>Rome constitutes one of Italy’s 8,101 communes, and is the largest both in   
  14.           terms of land area and population. It is governed by a mayor, currently    
  15.           Gianni Alemanno, and a city council. p>  
  16.      div>  
  17.    div>  
  18.   
  19.    <div data-role=“collapsible”>  
  20.      <h2>Madridh2>  
  21.      <div data-role=“collapsible”>  
  22.        <h3>Historyh3>  
  23.        <p>Although the site of modern-day Madrid has been occupied since pre-historic   
  24.           times,[23] in the Roman era this territory belonged to the diocese of   
  25.           Complutum (present-day Alcalá de Henares).p>  
  26.      div>  
  27.      <div data-role=“collapsible” data-collapsed=“true”>  
  28.        <h3>Governmenth3>  
  29.        <p>The City Council consists of 57 members, one of them being the Mayor,   
  30.           currently Alberto Ruiz-Gallardón Jiménez. The Mayor presides over the   
  31.           Council.p>  
  32.      div>  
  33.    div>  
  34. div>  

Rome

History

There is archaeological evidence of human occupation of the Rome area from at least 14,000 years, but the dense layer of much younger debris obscures Palaeolithic and Neolithic sites.[11] Evidence of stone tools, pottery and stone weapons attest to at least 10,000 years of human presence.

Government

Rome constitutes one of Italy's 8,101 communes, and is the largest both in terms of land area and population. It is governed by a mayor, currently Gianni Alemanno, and a city council.

Madrid

History

Although the site of modern-day Madrid has been occupied since pre-historic times,[23] in the Roman era this territory belonged to the diocese of Complutum (present-day Alcalá de Henares).

Government

The City Council consists of 57 members, one of them being the Mayor, currently Alberto Ruiz-Gallardón Jiménez. The Mayor presides over the Council.

手风琴部件(多个可折叠内容)
[html] view plain copy
print ?
  1. <div data-role=“page” id=“home”>  
  2.   
  3.    <div data-role=“header”>  
  4.         <h1>@firth1>  
  5.    div>  
  6.   
  7.    <div data-role=“content” data-theme=“b”>  
  8.   
  9.         
  10.         <div data-role=“collapsible-set”>  
  11.          <div data-role=“collapsible” data-collapsed=“false”>  
  12.                 <h2>Booksh2>  
  13.              <ul>  
  14.                 <li>Programming the Mobile Webli>  
  15.                 <li>jQuery Mobile: Up & Runningli>  
  16.                 <li>Mobile HTML5li>  
  17.              ul>  
  18.          div>  
  19.          <div data-role=“collapsible” data-collapsed=“true”>  
  20.                 <h2>Talksh2>  
  21.              <ul>  
  22.                 <li>Velocity Conferenceli>  
  23.                 <li>OSCONli>  
  24.                 <li>Mobile World Congressli>  
  25.                 <li>Google DevFestli>  
  26.              ul>  
  27.          div>  
  28.        div>  
  29.         
  30.   
  31.    div>  
  32.   
  33. div>  
  34.       

@firt

Books

  • Programming the Mobile Web
  • jQuery Mobile: Up & Running
  • Mobile HTML5

Talks

  • Velocity Conference
  • OSCON
  • Mobile World Congress
  • Google DevFest

3.排版(类似表格)
网格不可见,占100%的宽度,没有内外边距,可定义2-5列
ui-grid-a表示2列,ui-grid-b表示3列,ui-grid-c表示4列,ui-grid-d表示5列;
ui-block-a/b/c/d/e分别表示网格的第一列至第五列。
[html] view plain copy
print ?
  1. <div data-role=“content”>  
[html] view plain copy
print ?
  1. <pre name=“code” class=“html”>  <section class=“ui-grid-a”>  
  2.     <div class=“ui-block-a”>Column 1div>  
  3.     <div class=“ui-block-b”>Column 2div>  
  4.   section>  
  
Column 1
Column 2
[html] view plain copy
print ?
  1.   
  2.    <div class=“ui-block-a”>Cell 1.1div>  
  3.    <div class=“ui-block-b”>Cell 1.2div>  
  4.    <div class=“ui-block-c”>Cell 1.3div>  
  5.      
  6.    <div class=“ui-block-a”>Cell 2.1div>  
  7.    <div class=“ui-block-b”>Cell 2.2div>  
  8.    <div class=“ui-block-c”>Cell 2.3div>  
  9.  section>  
  10. lt;/div>  
 
    
Cell 1.1
Cell 1.2
Cell 1.3
Cell 2.1
Cell 2.2
Cell 2.3



4.按钮
创建按钮的三种方式: button元素/input type=”button”/data-role=”button”,默认情况下占满整个屏幕。
[html] view plain copy
print ?
  1. <a href=“#” data-role=“button”>Click me!a>  
  2. <button data-theme=“b”>Click me too!button>  
  3. <input type=“button” value=“Don’t forget about me!”>  
Click me!

内联按钮:data-inline=”true”,这种按钮不会占满屏幕宽度
[html] view plain copy
print ?
  1. <a href=“#” data-role=“button” data-inline=“true”>Button 1a>  
Button 1
按钮组:
[html] view plain copy
print ?
  1. <div <span style=“background-color: rgb(51, 204, 255);”>data-role=“controlgroup”span>>  
  2.   <a href=“#” data-role=“button”>Button 1a>  
  3.   <a href=“#” data-role=“button”>Button 2a>  
  4.   <a href=“#” data-role=“button”>Button 2a>  
  5. div>  
data-role="controlgroup"> Button 1 Button 2 Button 2
一行按钮(少于5个)
[html] view plain copy
print ?
  1. <div data-role=“controlgroup” <span style=“background-color: rgb(51, 204, 255);”>data-type=“horizontal”span>>  
  2.   <a href=“#” data-role=“button” data-inline=“true”>Button 1a>  
  3.   <a href=“#” data-role=“button” data-inline=“true”>Button 2a>  
  4.   <a href=“#” data-role=“button” data-inline=“true”>Button 2a>  
  5. div>  
data-type="horizontal"> Button 1 Button 2 Button 2
效果:data-shadow=”false”不带阴影 data-corners=”false”不带圆角
[html] view plain copy
print ?
  1. <a href=”#” data-role=”button” data-shadow=”false” data-corners=”false”>Helpa>  
Help
按钮自定义图标:图标应该是白色或透明的背景,18X18像素,高分辨率设备 (ios)下36X36像素,data-iconshadow=”false”移除图标阴影效果
[html] view plain copy
print ?
  1. <style>  
  2.    .ui-icon-myapp-tweet {  
  3.        background-image: url(icons/tweet.png);  
  4.    }  
  5.    @media only screen and (-webkit-min-device-pixel-ratio: 2) {  
  6.       .ui-icon-myapp-tweet {  
  7.           background-image: url(icons-hd/tweet.png) !important;  
  8.             background-size: 18px 18px;  
  9.       }  
  10. }  
  11. style><pre name=“code” class=“html”><a href=“#” data-role=“button” data-icon=“myapp-tweet”>Tweeta>  
Tweet
 图标位置:相对文字的位置data-iconpos
[html] view plain copy
print ?
  1. <a href=“#” data-role=“button” data-icon=“help” data-iconpos=“right”>Helpa>  
  2. <a href=“#” data-role=“button” data-icon=“help” data-iconpos=“left”>Helpa>  
  3. <div data-role=“controlgroup”>  
  4.   <a href=“#” data-role=“button” data-icon=“help” data-iconpos=“bottom”>Helpa>  
  5.   <a href=“#” data-role=“button” data-icon=“help” data-iconpos=“top”>Helpa>  
  6. div>  
Help
Help

JM图标汇总
图标 图标
向左箭头 arrow-l 刷新 refresh
向右箭头 arrow-r 向前动作 forward
向上箭头 arrow-u 向后动作 back
向下箭头 arrow-d 网格 grid
删除(X) delete 星星 star
加号 plus 警报(警号) alert
减号 minus 信息(i) info
检查标记(√) check 主页图标 home
齿轮图标 gear 搜索图标 search


你可能感兴趣的:(jQuery Mobile学习笔记(三)——UI组件)