Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
jQuery Mobile Web Development Essentials-Third Edition

You're reading from   jQuery Mobile Web Development Essentials-Third Edition Build a powerful and practical jQuery-based framework in order to create mobile-optimized websites

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783555055
Length 266 pages
Edition 3rd Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Andy Matthews Andy Matthews
Author Profile Icon Andy Matthews
Andy Matthews
Raymond Camden Raymond Camden
Author Profile Icon Raymond Camden
Raymond Camden
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Preparing Your First jQuery Mobile Project FREE CHAPTER 2. Working with jQuery Mobile Pages 3. Enhancing Pages with Headers, Footers, and Toolbars 4. Working with Lists 5. Getting Practical – Building a Simple Hotel Mobile Website 6. Working with Forms and jQuery Mobile 7. Creating Grids, Panels, and Other Widgets 8. Moving Further with the Notekeeper Mobile Application 9. jQuery Mobile Configuration, Utilities, and JavaScript Methods 10. Working with Events 11. Enhancing jQuery Mobile 12. Creating Native Applications 13. Becoming an Expert – Building an RSS Reader Application Index

Implementing jQuery Mobile

Ok, we've got the bits. How do we use them? Adding jQuery Mobile support to a website requires the following three steps at a minimum:

  1. First, add the HTML5 DOCTYPE declaration to the page:
    <!DOCTYPE html>
    

    This is used to help inform the browser about the type of content it will be dealing with

  2. Add a viewport meta tag:
    <meta name="viewport" content="width=device-width, initial-scale=1">
    

    This will help set better defaults for pages when viewed on a mobile device

  3. Finally, the CSS, the JavaScript library, and jQuery itself need to be included into the file.

Let's look at a modified version of our previous HTML file that adds all of these:

Listing 1-2: test2.html
<!DOCTYPE html>
<html>
  <head>
    <title>First Mobile Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="jquery.mobile-1.4.5.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script type="text/javascript" src="jquery.mobile-1.4.5.min.js"></script>
  </head>
  <body>
    <h1>Welcome</h1>
     <p>
       Welcome to our first mobile web site.
       It's going to be the best site you've ever seen.
       Once we get some content. And a business plan.
       But the hard part is done!
     </p>
    <p>
      <i>Copyright Megacorp &copy; 2015</i>
    </p>
  </body>
</html>

For the most part, this version is the exact same as listing 1, except for the addition of the DOCTYPE declaration, the CSS link, and our two JavaScript libraries. Notice that we pointed to the hosted version of the jQuery library. It's perfectly fine to mix local JavaScript files and remote ones. If you want to ensure that you can work offline, you can simply download the jQuery library as well.

So, while nothing changed in the code between the body tags, there is going to be a radically different view now in the browser. The following screenshot shows how the iOS mobile browser renders the page now:

Implementing jQuery Mobile

Right away, you see a couple of differences. The biggest difference is the relative size of the text. Notice how much bigger and easier to read it is. As we said, the user could have zoomed in on the previous version, but many mobile users aren't aware of this technique. This page loads up immediately in a manner that is much more usable on a mobile device.

You have been reading a chapter from
jQuery Mobile Web Development Essentials-Third Edition - Third Edition
Published in: Mar 2016
Publisher:
ISBN-13: 9781783555055
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image