Archive

Posts Tagged ‘Navbar’

How to add Navbar in your jQuery Mobile site.

Navibar is one of the easy way to navigate web site and friendly to users. jQuery Mobile already has basic navbar widget to add navbar in your website easily.

See following source code. You can notice navbar widget starts with a div of data-role=”navbar”. It can have up to five buttons in the current version (1.0rc1)

Also very important thing to remember is hot to highlight active an item in the navbar. To  set one of the links to be shown as selected state,  add class=”ui-btn-active ui-state-persist” to <a> tag.

<!DOCTYPE html>
<html>
<head>
  <title>Test Navbar</title>
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
  <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
  <script src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
</head>
<body>
  <!-- First page -->
  <div data-role="page" id="first">
    <div data-role="header">
      <!-- Title Header -->
      <h1>Page Title</h1>
      <!-- Navbar -->
      <div data-role="navbar">
        <ul>
          <li><a href="#first">First</a></li>
          <li><a href="#second">Second</a></li>
        </ul>
      </div>
    </div>
    <div data-role="content">
      <p>You are in the First page.</p>
      <p>Tip: If you'd like to an item in your navbar, add a class of "ui-btn-active ui-state-persist" in the link.</p>
    </div>
    <div data-role="footer">
      <h4>Page Footer</h4>
    </div>
  </div>

  <!-- Second page -->
  <div data-role="page" id="second">
    <div data-role="header">
      <!-- Title Header -->
      <h1>Page Title</h1>
      <!-- Navbar -->
        <div data-role="navbar">
        <ul>
          <li><a href="#first">First</a></li>
          <li><a href="#second">Second</a></li>
        </ul>
      </div>
    </div>
    <div data-role="content">
      <p>You are in the Second page.</p>
      <p>Tip: If you'd like to an item in your navbar, add a class of "ui-btn-active ui-state-persist" in the link.</p>
    </div>
    <div data-role="footer">
      <h4>Page Footer</h4>
    </div>
  </div>
</body>
</html>
Advertisements
Categories: Blog, jQuery Mobile Tags: ,