Home > Blog, jQuery Mobile > How to add Navbar in your jQuery Mobile site.

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: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: