Linking pages

As mentioned, we can define multiple pages div in jQuery mobile. And actually we can link between them with anchor and hash query as same as building normal website.

So we can create another full screen view with another data-role=page.

We will create a button inside the header that links to the about page.

 1<!-- Root page -->
 2<div data-role='page' id='root'>
 3  <div data-role='header'>
 4    <h1>TwentyFive</h1>
 5    <a class='ui-btn-right' data-role='button' href='#about'>關於</a>
 6  </div>
 7  <div data-role='content'>
 8    <p id='timer'>00:00</p>
 9    <a data-role='button' id='reset'>重新計時</a>
10  </div>
13<!-- About page -->
14<div data-role='page' id='about'>
15  <div data-role='header'>
16    <h2>關於</h2>
17    <a data-icon='arrow-l' data-rel='back'>TwentyFive</a>
18  </div>
19  <div data-role='content'>
20    <p>這是一個 25 分鐘倒計時器。運用了一種稱為 <a href=''>Pomodoro</a> 的工作時間分配技巧。</p>
21    <p>電話:<a href='tel:+85366331234'>+853 6633 1234</a></p>
22    <p>電郵:<a href=''></a></p>
23  </div>

Let’s take a look at the result.

Twenty five buttons

What the code just did?

We learnt a new data-* attribute named data-button which generates the button style for us.

Please note that the button style inside header section and in the content page is different, although they share the same HTML code.

And actually I feel uncomfortable to the rounded corner by jQuery mobile. So we can override it in our CSS styling. We know the .ui-but-corner-all class because we use the Chrome Inspector to detect it.

1/* override */
2.ui-btn-corner-all {
3  border-radius: 5px;

How about linking back from the about view? We can use data-rel=back for this purpose.

While doing the linking, we use the same technique from web design. We link to the #a_name_of_page.

Throughout the using of jQuery mobile, you will find that it follows quite a lot practice of writing normal web page. It is because it’s aim is to make web designer transits to mobile development as easy as possible.

What’s next? We’re going to take a look at “Timer logic — Entry point”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content