Wednesday, December 11, 2013

jQuery mobile example



jQuery mobile is a web framework to build mobile websites using HTML5 and CSS3.
Reference:
http://jquerymobile.com/
http://www.w3schools.com/jquerymobile/jquerymobile_examples.asp

Example code
1) Call jQuery library:
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
2) Call  jQuery mobile library
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
3)  Using jQuery mobile CSS
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
4) Define viewport for mobile
<meta name="viewport" content="width=device-width, initial-scale=1">
5) Define a header
<div data-role="header">
    <h4>jQuery Mobile  </h4>
  </div>

6) Define page content
 <div data-role="content"></div>
7) Define footer
 <div data-role="footer">
    <h4>&copy; 2013 Jiansen Lu</h4>
  </div>

8) complete example1.html
<!DOCTYPE html>
<html>
<head>
 <title>jQuery Mobile code example</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h4>jQuery Mobile  </h4>
  </div>

  <div data-role="content">
     <ul data-role="listview" data-inset="true" data-dividertheme="b">
                     <li data-role="list-divider">Options</li>
                     <li><a href="menu.html">Food menu</a></li>
                     <li><a href="">Location</a></li>
                     <li><a href="">Search Nearby</a></li>
                     <li><a href="">Contact us</a></li>
               </ul>          
  </div>

  <div data-role="footer">
    <h4>&copy; 2013 Jiansen Lu</h4>
  </div>
</div>

</body>
</html>

9) The link menu.html
<!DOCTYPE html>
<html>
<head>
 <title>Food Menu</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div data-role="page" id="home" data-theme="c">
<div data-role="content">
<div id="branding">
<h1>Food  Menu </h1>
</div>
<div class="choice_list">
<ul data-role="listview" data-inset="true" >
<li><a href="" data-transition="slidedown"> <img src="seaweedtofu.JPG"/> <h3> Sea Weed ToFu </h3></a></li>
<li><a href="" data-transition="slidedown"> <img src="shrimpdumpling.JPG"/> <h3> Shrimp Dumpling </h3></a></li>
<li><a href="" data-transition="slidedown"> <img src="boiledegg.JPG"/> <h3> Boiled Eggs</h3></a></li>
<li><a href="" data-transition="slidedown"> <img src="Congee.JPG"/> <h3> Congee</h3></a></li>
<li><a href=" " data-transition="slidedown"> <img src="snowpeas.JPG"/> <h3> Snow Peas </h3></a></li>
</ul>
</div>
</div>
</div><!-- /page -->
</body>
</HTML>

10) Demo page:
http://swf.site40.net/jquerymobile/example1.html

1 comment: