0

JQuery Mobile – Lesson 05 – Navbar – Buttons and more

JQuery Mobile – Lesson 05 – Navbar – Buttons and more

Lesson 01 | Lesson 02 | Lesson 03 | Lesson 04 | Lesson 05


1. At this lesson we will continue from Lesson 03.

2. Here is the HTML Code from Lesson 03 with changes marked with RED color:

A navbar will appear with two buttons.

You can also download the following content as a file from HERE.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page title</title> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
    <div data-role="page" id="page1" data-theme="b">
       <div data-role="header">
       <h1>Page 1 header</h1>
          <div data-role="navbar">
             <ul>
                <li><a href="#page1">Home</a></li>
                <li><a href="#page2">Contact</a></li>
             </ul>
          </div>             
       </div> 
       <div data-role="main" class="ui-content">
       <h1>Page 1 Main</h1>
       <a href="#page2" data-transition="flow">page 2</a>      
       </div>

       <div data-role="footer">
       <h1>Page 1 footer</h1>
       </div>
    </div>

    <div data-role="page" id="page2" data-theme="b">
       <div data-role="header">
       <h1>Page 2 header</h1>
          <div data-role="navbar"> 
            <ul>
               <li><a href="#page1">Home</a></li>
               <li><a href="#page2">Contact</a></li>
            </ul>
           </div>
    </div>        
    <div data-role="main" class="ui-content">
        <h1>Page 2 Main</h1>        
           <a href="#page1" data-transition="flow">page 1</a>        
    </div>        
    <div data-role="footer">        
      <h1>Page 2 footer</h1>        
   </div>     
</div> 
</body> 
</html>

3. Now let’s add icons to the navbar by adding to the following line, we will see buttons with icon of grid:

<li><a href="#page1" data-icon="grid">Home</a></li>

Click on this link for list of icons
4. At this point we can remove the following lines under data-role=”main”:

<a href=”#page1″ data-transition=”flow”>page 1</a>

5. Now let’s add the following block code under data=role=”main”:

<div data-role="collapsible">
  <h1>Click here to view what is under this button</h1>
  <p>There is nothing here</p>
</div>

Here is an example of collapsible:

6. At this point add the code mark with RED color, you code suppose to be look like the following:

Copy & Paste the following and see what is the output:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
<title>Page title</title> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> 
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
</head> 
<body> 
<div data-role="page" id="page1" data-theme="a"> 
<div data-role="header"> 
<h1>Page 1 header</h1> 
<div data-role="navbar"> 
<ul> 
<li><a href="#page1" data-icon="action">Home</a></li> 
<li><a href="#page2" data-icon="alert">Contact</a></li> 
</ul> 
</div> 
</div> 
<div data-role="main" class="ui-content"> 
<h1>Page 1 Main</h1> 
 <div data-role="collapsible">
 <h1>Click here to view what is under this button</h1>
 <p>There is nothing here</p>
 </div>
</div> 
<div data-role="footer"> 
<h1>Page 1 footer</h1> 
</div> 
</div> 
 <div data-role="page" id="page2" data-theme="a"> 
 <div data-role="header"> 
 <h1>Page 2 header</h1> 
 <div data-role="navbar"> 
 <ul> 
 <li><a href="#page1" data-icon="grid">Home</a></li> 
 <li><a href="#page2" data-icon="grid">Contact</a></li> 
 
 </ul> 
 </div> 
 </div> 
 <div data-role="main" class="ui-content"> 
 <h1>Page 2 Main</h1> 
 <form>
 <textarea></textarea>
 <input type="range" min="0" max="10">
 <input type="submit" value="submit button">
 </form>
 </div> 
 <div data-role="footer"> 
 <h1>Page 2 footer</h1> 
 </div> 
 </div> 
</body> 
</html>