9780596805784
chapAnimation.html

Chapter 4. Animation

This book is published and is no longer accepting comments on OFPS. Please consider purchasing the print book or ebook. Thank you for supporting OFPS!

iPhone apps have a number of distinctive animation characteristics that add context and meaning for the user. For example, pages slide left as you drill down through links, and slide right as you navigate back. In this chapter, you’ll learn how to add characteristic behaviors like sliding, page flip, and more to your web app. These changes, in combination with Ajax and full screen mode, will make your web app almost indistinguishable from a native application.

With a Little Help from Our Friend

I’ll be honest: making a web page animate like a typical native iPhone app is hard. Fortunately, an enterprising young lad from Philly named David Kaneda has written a JavaScript library called jQTouch that makes mobile web development a whole lot easier. jQTouch is an open source jQuery plug-in that handles virtually everything we learned in the previous chapter, as well as a boatload of much more complex stuff that would be truly painful to write from scratch.

Note

You can download the latest version of jQTouch from http://jqtouch.com/.

Sliding Home

We are going to build a simple calorie-tracking application called Kilo that allows the user to add and delete food entries for a given date. All told, there will be five panels: Home, Settings, Dates, Date, and New Entry. We’ll start off with two panels and work our way up as we go.

Note

I’ll be assigning CSS classes to some of the HTML elements (toolbar, edgetoedge, arrow, button, back, etc.). In every case, these classes correspond to predefined CSS class selectors that exist in the default jQTouch theme. Bear in mind that you can create and use your own classes by modifying existing jQTouch themes or building your own from scratch; I’m just using the defaults.

To begin, let’s create a file named index.html and add the HTML shown in Example 4.1, “HTML for the Home and About panels in index.html” for the Home and About panels.

Figure 4.1. Kilo before jQTouch...

Kilo before jQTouch...

Example 4.1. HTML for the Home and About panels in index.html

<html>
    <head>
        <title>Kilo</title>
    </head>
    <body>
        <div id="home">1
            <div class="toolbar">2
                <h1>Kilo</h1>
            </div>
            <ul class="edgetoedge">3
                <li class="arrow"><a href="#about">About</a></li>4
            </ul>
        </div>
        <div id="about">
            <div class="toolbar">
                <h1>About</h1>
                <a class="button back" href="#">Back</a>5
            </div>
            <div>
                <p>Kilo gives you easy access to your food diary.</p>
            </div>
        </div>
    </body>
</html>

The HTML here basically amounts to a head with a title, and a body with two children, both divs:

1

This div (as well as the about div that appears a few lines down) will become a panel in the application by virtue of the fact that it is a direct descendant of the body.

2

Inside each panel div, there is a div with a class of toolbar. This toolbar class is specifically predefined in the jQTouch themes to style an element like a traditional iPhone toolbar.

3

This unordered list tag has the class edgetoedge. The edgetoedge class tells jQTouch to stretch the list all the way from left to right in the viewable area.

4

On this line there is an li that contains a link with its href pointing at the About panel. Including the arrow class to the li is optional; doing so will add a chevron to the right side of the item in the list.

5

The toolbar elements each contain a single h1 element that will become the panel title. On this line, there is a link with the classes button and back, which tell jQTouch to make the button look and act like a back button.

Note

Note that the href on the back button is set to #. Normally, this would tell the browser to return to the top of the current document. But when using jQTouch, it navigates back to the previous panel instead. In more advanced scenarios, you might want to use a specific anchor, such as #home, which would instruct the back button to navigate to a particular panel regardless of what the previous panel was.

With the basic HTML in place, it’s time to add jQTouch to the party. Once you’ve downloaded jQTouch and unzipped it in the same directory as the HTML document, you just add a few lines of code to the head of your page (Example 4.2, “Adding these lines to the head of your document will activate jQTouch”).

Note

For this and other examples in this book, you will need to download jQTouch from http://jqtouch.com, unzip it, and move the jqtouch and themes directories into the same directory as your HTML document. You will also need to go into the jqtouch directory and rename the jQuery JavaScript file (such as jquery.1.3.2.min.js) to jquery.js.

Example 4.2. Adding these lines to the head of your document will activate jQTouch

<link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css">1
<link type="text/css" rel="stylesheet" media="screen" href="themes/jqt/theme.css">2
<script type="text/javascript" src="jqtouch/jquery.js"></script>3
<script type="text/javascript" src="jqtouch/jqtouch.js"></script>4
<script type="text/javascript">5
    var jQT = $.jQTouch({
        icon: 'kilo.png',
        statusBar: 'black'
    });
</script>

1

I’m including the jqtouch.css file. This file defines some hardcore structural design rules that are very specific to handling animations, orientation, and other iPhone-specific minutiae. This file is required and there should be no reason for you to edit it.

2

I’m including the CSS for my selected theme, in this case, the “jqt” theme, which comes with jQTouch. The classes that I’ve been using in the HTML correspond to CSS selectors in this document. jQTouch comes with two themes available by default. You can also make your own by duplicating a default theme and making changes to it, or writing a new one from scratch.

3

jQTouch requires jQuery, so I include that here. jQTouch comes with its own copy of jQuery, but you can link to another copy if you prefer.

4

This is where I include jQTouch itself. Note that you have to include jQTouch after jQuery, or nothing’s going to work.

5

This brings us to the script block where I initialize the jQTouch object and send in two property values: icon and statusBar.

jQTouch exposes several properties that allow you to customize the behavior and appearance of your app. You’ll see several throughout the course of this book, and they are all optional. However, you’ll pretty much always be using at least a few of them.

In this case, icon tells jQTouch where to look for the custom Web Clip icon, and statusBar controls the color of the 20px strip at the top of the app in full screen mode.

Note

By the way, jQTouch assumes that you want the app to run in full screen mode because, hey...that’s how you roll. If you’d prefer to disallow full screen mode, you can add fullScreen: false to the property list.

The difference between the application before jQTouch (Figure 4.1, “Kilo before jQTouch...”) and after (Figure 4.2, “...and Kilo after jQTouch”) is dramatic, but the truly astonishing thing is that you’ve just added gorgeous left/right sliding to your app with 10 lines of code. What’s more, you’ve also enabled full screen mode, defined a custom status bar color, and linked to your Web Clip icon. jQTouch is completely sick, and we’re just getting started.

Figure 4.2. ...and Kilo after jQTouch

...and Kilo after jQTouch

Adding the Dates Panel

Let’s now add the Dates panel. The Dates panel will have a list of relative dates beginning with Today and going back to 5 days ago (Figure 4.3, “The Dates panel consists of a toolbar with a back button and a clickable list of relative dates”). Add the HTML for the Dates panel (shown in Example 4.3, “The HTML for the Dates panel”) right after the About panel, just before the closing </body>.

Example 4.3. The HTML for the Dates panel

<div id="dates">
    <div class="toolbar">
        <h1>Dates</h1>
        <a class="button back" href="#">Back</a>
    </div>
    <ul class="edgetoedge">
        <li class="arrow"><a id="0" href="#date">Today</a></li>
        <li class="arrow"><a id="1" href="#date">Yesterday</a></li>
        <li class="arrow"><a id="2" href="#date">2 Days Ago</a></li>
        <li class="arrow"><a id="3" href="#date">3 Days Ago</a></li>
        <li class="arrow"><a id="4" href="#date">4 Days Ago</a></li>
        <li class="arrow"><a id="5" href="#date">5 Days Ago</a></li>
    </ul>
</div>

Figure 4.3. The Dates panel consists of a toolbar with a back button and a clickable list of relative dates

The Dates panel consists of a toolbar with a back button and a clickable list of relative dates

Like the About panel, the Dates panel has a toolbar with a title and back button. After the toolbar, there is an unordered edgetoedge list of links. Notice that all of the links have unique ids (0 through 5) but the same href (#date)—more on that in a bit.

Next, you have to update the Home panel with a link to the Dates panel. Add the following line to the Home panel in index.html:

<div id="home">
    <div class="toolbar">
        <h1>Kilo</h1>
    </div>
    <ul class="edgetoedge">
        <li class="arrow"><a href="#dates">Dates</a></li>
        <li class="arrow"><a href="#about">About</a></li>
    </ul>
</div>

And just like that, we’ve added a new panel to the app (see Figure 4.4, “The Home panel now has a link to the Dates panel”). Clicking on an item on the Dates panel doesn’t do anything yet. Let’s rectify that situation by adding the Date panel.

Adding the Date Panel

The Date panel looks a lot like the previous panels, with a couple of exceptions (refer to Example 4.4, “The HTML for the Date panel”). Add the HTML for the Date panel right after the Dates panel, just before the closing </body>.

Example 4.4. The HTML for the Date panel

<div id="date">
    <div class="toolbar">
        <h1>Date</h1>
        <a class="button back" href="#">Back</a>
        <a class="button slideup" href="#createEntry">+</a>1
    </div>
    <ul class="edgetoedge">
        <li id="entryTemplate" class="entry" style="display:none">2
            <span class="label">Label</span>
            <span class="calories">000</span>
            <span class="delete">Delete</span>
        </li>
    </ul>
</div>

1

The Date panel toolbar has an additional button. When clicked, this button will display the New Entry panel (which we have not yet built). I’ve given the link a class of slideup, which tells jQTouch that we want the target panel to slide up from the bottom of the screen, rather than horizontally like typical navigation.

2

The other unusual aspect of this panel is that I’ve defined a list item with the style set to display:none, effectively making it invisible.

As you’ll see in a bit, I’m going to use this invisible list item as a template to display entries once they are created. At this point, there are no entries, so the panel will be empty aside from the toolbar.

Now that you’ve added the Date panel, clicking any item on the Dates panel will slide the empty Date panel (Figure 4.5, “Apart from the toolbar, the Date panel is empty to begin with”) into view.

Figure 4.5. Apart from the toolbar, the Date panel is empty to begin with

Apart from the toolbar, the Date panel is empty to begin with

Adding the New Entry Panel

Example 4.5, “The HTML for the New Entry panel” shows the source code for the New Entry panel. Add this code to the end of index.html, just before the closing </body>.

Example 4.5. The HTML for the New Entry panel

<div id="createEntry">
    <div class="toolbar">
        <h1>New Entry</h1>
        <a class="button cancel" href="#">Cancel</a>1
    </div>
    <form method="post">2
        <ul>
            <li><input type="text" placeholder="Food" name="food" id="food" 
                 autocapitalize="off" autocorrect="off" autocomplete="off" /></li>
            <li><input type="text" placeholder="Calories" name="calories" id="calories" 
                 autocapitalize="off" autocorrect="off" autocomplete="off" /></li>
            <li><input type="submit" class="submit" name="action"
                value="Save Entry" /></li>3
        </ul>
    </form>
</div>

1

The first thing to point out about the New Entry panel is that instead of having a back button, it has a cancel button.

Note

Cancel buttons in jQTouch behave just like back buttons, in that they remove the current page from view using the reverse animation of the way it came into view. However, unlike back buttons, cancel buttons are not shaped like a left arrow.

I used a cancel button for the New Entry panel because it slides up on the way in and will therefore slide down on the way out. It would be counterintuitive to click a left-pointing back button and then have the panel slide down.

2

This HTML form contains an unordered list of three items: two text fields and a submit button. Embedding form controls in an li allows the jqt theme to style the form as shown in Figure 4.6, “The jqt theme does a nice job styling form elements”.

Each of the text inputs has quite a few defined attributes:

type

Defines the form control to be a single-line text entry field.

placeholder

A string of text to display in the form input when the input is empty.

name

The name that will be associated with the value provided by the user when the form is submitted.

id

A unique identifier for the element in the context of the entire page.

autocapitalize

A Mobile Safari–specific setting that allows you to turn off the default autocapitalization feature.

autocorrect

A Mobile Safari–specific setting that allows you to turn off the default spellcheck feature.

autocomplete

Setting that allows you to turn off the autocomplete feature of Mobile Safari.

3

The class attribute of the submit input button needs explanation. The iPhone will display a keyboard whenever your cursor is in a field. The keyboard has a Go button in the bottom-right corner that submits the form when clicked. When you are hijacking the submit function as we are doing here, submitting from the Go button on the keyboard does not remove the cursor from the active field, and therefore the keyboard does not slide out of view. To remedy this, jQTouch offers a convenience method that automatically removes the cursor from the active field when a form is submitted. To take advantage of this feature, you just add the submit class to the submit element of the form.

Figure 4.6. The jqt theme does a nice job styling form elements

The jqt theme does a nice job styling form elements

Figure 4.7, “Keyboard data entry with the New Entry form” shows the New Entry form in action. At this point, I’ve done nothing to actually save the entry when the user clicks Save Entry. We’ll cover that in Chapter 5, Client-Side Data Storage.

Figure 4.7. Keyboard data entry with the New Entry form

Keyboard data entry with the New Entry form

Adding the Settings Panel

We haven’t yet created a button that will allow users to navigate to the Settings panel, so let’s add one to the toolbar on the Home panel (see Figure 4.8, “The Settings button added to the toolbar on the Home panel”). All it takes is a single line of HTML, shown in bold:

<div id="home">
    <div class="toolbar">
        <h1>Kilo</h1>
        <a class="button flip" href="#settings">Settings</a>1
    </div>
    <ul class="edgetoedge">
        <li class="arrow"><a href="#dates">Dates</a></li>
        <li class="arrow"><a href="#about">About</a></li>
    </ul>
</div>

1

This is the line of HTML that adds the button. Notice that I’ve assigned the flip class to the link. The flip class instructs jQTouch to transition from the Home panel to the Settings panel by rotating the page on its vertical axis. To add an extra dimension to the process, the page actually zooms out a bit during the animation, similar to the default Weather app on the iPhone. Fancy, no?

Figure 4.8. The Settings button added to the toolbar on the Home panel

The Settings button added to the toolbar on the Home panel

In comparison with the New Entry panel, the HTML for the Settings panel is going to look pretty familiar (Example 4.6, “The HTML for the Settings panel”). There is one more text input and some of the attributes have been omitted or have different values, but conceptually they are identical. Add this to your HTML document just as you’ve done for the other panels. When you’re done, the Settings panel should look like Figure 4.9, “The Settings panel”.

As with the New Entry form, the Settings form does not currently save any of the information associated with it. Its submission handler will be described in the next chapter.

Example 4.6. The HTML for the Settings panel

<div id="settings">
    <div class="toolbar">
        <h1>Settings</h1>
        <a class="button cancel" href="#">Cancel</a>
    </div>
    <form method="post">
        <ul>
            <li><input placeholder="Age" type="text" name="age" id="age" /></li>
            <li><input placeholder="Weight" type="text" name="weight" id="weight" /></li>
            <li><input placeholder="Budget" type="text" name="budget" id="budget" /></li>
            <li><input type="submit" class="submit" name="action" 
                value="Save Changes" /></li>
        </ul>
    </form>
</div>

Figure 4.9. The Settings panel

The Settings panel

Putting It All Together

So there you have it. With fewer than 100 lines of code, we’ve created an iPhone-esque UI for a five-panel application, complete with three different page transition animations. Not too shabby, right? See Example 4.7, “The complete HTML listing for the five-panel UI” for a complete listing of the final HTML.

Example 4.7. The complete HTML listing for the five-panel UI

<html>
    <head>
        <title>Kilo</title>
        <link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css">
        <link type="text/css" rel="stylesheet" media="screen" 
            href="themes/jqt/theme.css">
        <script type="text/javascript" src="jqtouch/jquery.js"></script>
        <script type="text/javascript" src="jqtouch/jqtouch.js"></script>
        <script type="text/javascript">
            var jQT = $.jQTouch({
                icon: 'kilo.png',
                statusBar: 'black'
            });
        </script>
    </head>
    <body>
        <div id="home">
            <div class="toolbar">
                <h1>Kilo</h1>
                <a class="button flip" href="#settings">Settings</a>
            </div>
            <ul class="edgetoedge">
                <li class="arrow"><a href="#dates">Dates</a></li>
                <li class="arrow"><a href="#about">About</a></li>
            </ul>
        </div>
        <div id="about">
            <div class="toolbar">
                <h1>About</h1>
                <a class="button back" href="#">Back</a>
            </div>
            <div>
                <p>Kilo gives you easy access to your food diary.</p>
            </div>
        </div>
        <div id="dates">
            <div class="toolbar">
                <h1>Dates</h1>
                <a class="button back" href="#">Back</a>
            </div>
            <ul class="edgetoedge">
                <li class="arrow"><a id="0" href="#date">Today</a></li>
                <li class="arrow"><a id="1" href="#date">Yesterday</a></li>
                <li class="arrow"><a id="2" href="#date">2 Days Ago</a></li>
                <li class="arrow"><a id="3" href="#date">3 Days Ago</a></li>
                <li class="arrow"><a id="4" href="#date">4 Days Ago</a></li>
                <li class="arrow"><a id="5" href="#date">5 Days Ago</a></li>
            </ul>
        </div>
        <div id="date">
            <div class="toolbar">
                <h1>Date</h1>
                <a class="button back" href="#">Back</a>
                <a class="button slideup" href="#createEntry">+</a>
            </div>
            <ul class="edgetoedge">
                <li id="entryTemplate" class="entry" style="display:none">
                    <span class="label">Label</span>
                    <span class="calories">000</span>
                    <span class="delete">Delete</span>
                </li>
            </ul>
        </div>
        <div id="createEntry">
            <div class="toolbar">
                <h1>New Entry</h1>
                <a class="button cancel" href="#">Cancel</a>
            </div>
            <form method="post">
                <ul>
                    <li><input type="text" placeholder="Food" 
                        name="food" id="food" autocapitalize="off" 
                        autocorrect="off" autocomplete="off" /></li>
                    <li><input type="text" placeholder="Calories" 
                        name="calories" id="calories" autocapitalize="off" 
                        autocorrect="off" autocomplete="off" /></li>
                    <li><input type="submit" class="submit" name="action" 
                        value="Save Entry" /></li>
                </ul>
            </form>
        </div>
        <div id="settings">
            <div class="toolbar">
                <h1>Settings</h1>
                <a class="button cancel" href="#">Cancel</a>
            </div>
            <form method="post">
                <ul>
                    <li><input placeholder="Age" type="text" name="age" id="age" /></li>
                    <li><input placeholder="Weight" type="text" name="weight"
                        id="weight" /></li>
                    <li><input placeholder="Budget" type="text" name="budget" 
                        id="budget" /></li>
                    <li><input type="submit" class="submit" name="action" 
                        value="Save Changes" /></li>
                </ul>
            </form>
        </div>
    </body>
</html>

Customizing jQTouch

jQTouch allows you to customize its default behavior by sending a variety of property settings into the constructor. We’ve seen this previously with icon and statusBar, but there are many others that you should be aware of. See Table 4.1, “jQTouch customization options”.

Table 4.1. jQTouch customization options

PropertyDefaultExpectsNotes
addGlossToIcontruetrue or falseIf set to true, allow iPhone to add gloss to your Web Clip icon.
backSelector'.back, .cancel, .goback'Any valid CSS selector; separate multiple values with a commaDefines elements that will trigger the “back” behavior of jQTouch when tapped. When the back behavior is invoked, the current panel moves off screen with a reverse animation and is removed from history.
cacheGetRequeststruetrue or falseIf set to true, automatically caches GET requests, so subsequent clicks reference the already loaded data.
cubeSelector'.cube'Any valid CSS selector; separate multiple values with a commaDefines elements that will trigger a cube animation from the current panel to the target panel.
dissolveSelector'.dissolve'Any valid CSS selector; separate multiple values with a commaDefines elements that will trigger a dissolve animation from the current panel to the target panel.
fadeSelector'.fade'Any valid CSS selector; separate multiple values with a commaDefines elements that will trigger a fade animation from the current panel to the target panel.
fixedViewporttruetrue or falseIf set to true, prevents users from being able to zoom in or out on the page.
flipSelector'.flip'Any valid CSS selector; separate multiple values with a commaDefines elements that will trigger a flip animation from the current panel to the target panel.
formSelector'form'Any valid CSS selector; separate multiple values with a commaDefines elements that should be styled as a form by the CSS theme.
fullScreentruetrue or falseWhen set to true, your app will open in full screen mode when launched from the user’s home screen. Has no effect on the display if the app is running in Mobile Safari.
fullScreenClass'fullscreen'StringClass name that will be applied to the body when the app is launched in full screen mode. Allows you to write custom CSS that only executes in full screen mode.
iconnullnull or a relative or absolute path to a 57 × 57 px png image fileThe Web Clip icon for your app. This is the image that will be displayed when a user saves your app to her home screen.
popSelector'.pop'Any valid CSS selector; separate multiple values with a commaDefines elements that will trigger a pop animation from the current panel to the target panel.
preloadImagesfalseAn array of image paths to load before page loadsEx: ['images/link_over.png', 'images/link_select.png'].
slideInSelector'ul li a'Any valid CSS selector; separate multiple values with a commaDefines elements that will trigger a slide left animation from the current panel to the target panel.
slideupSelector'.slideup'Any valid CSS selector; separate multiple values with a commaDefines elements that will cause the target panel to slide up into view in front of the current panel.
startupScreennullnull or a relative or absolute path to an image filePass a relative or absolute path to a 320px × 460px startup screen for full-screen apps. Use a 320px × 480px image if you set statusBar to black-translucent.
statusBar'default'default, black-translucent, blackDefines the appearance of the 20-pixel status bar at the top of the window in an app launched in full screen mode.
submitSelector'.submit'Any valid CSS selector; separate multiple values with a commaSelector that, when clicked, will submit its parent form (and close keyboard if open).
swapSelector'.swap'Any valid CSS selector; separate multiple values with a commaDefines elements that will cause the target panel to swap into view in front of the current panel.
useAnimationstruetrue or falseSet to false to disable all animations.

What You’ve Learned

In this chapter, you’ve learned how to add native-looking animations to a web app using jQTouch. In the next chapter, you’ll learn how to use the new local storage and client-side database features of HTML5 to add persistent data storage to your app.

Site last updated on: September 7, 2011 at 07:00:43 AM PDT
Cover for Building iPhone Apps with HTML, CSS, and JavaScript

              View 3 comments

              1. bkendig – Posted July 1, 2010

                With the latest repository version of jQTouch, you need to put a div id="jqt" (lower-case is important; don't spell it "jQT") immediately inside the body tag, and put all of your other divs inside this jqt div instead of directly into the body tag.

              2. Adam Thede – Posted Feb. 4, 2011

                I don't believe bkendig's correction is necessary at this time.

              3. Adam Thede – Posted Feb. 4, 2011

                I don't think that's necessary with the current version.

                View 2 comments

                1. Itamar – Posted Feb. 11, 2010

                  Hey, Maybe i wrong, but maybe you missed to add: class="current"?

                  [Nice book!]

                2. jonathanstark – Posted Feb. 11, 2010

                  If you don't add class="current" to any panels, jQTouch will add "current" to the first panel automatically.

                    View 1 comment

                    1. Gennaro D'Orio – Posted Feb. 15, 2011

                      I've just installed jQTouch v1 beta2 and it seems to me that the "arrow" class on list items doesn't work if the unordered list has the "edgetoedge" class.

                            View 4 comments

                            1. the12thplaya – Posted Aug. 11, 2010

                              It looks like jQTouch requires jQuery 1.3.2 to work because I downloaded the latest version of jQuery (1.4.2) and if I include the above jqtouch.css line it gives me a black screen.

                              I only start seeing things on the screen if I remove the css file, but this unfortunately puts everything on the screen. After a good hour or so I got it working with an earlier version of jquery.js

                              The instructions on how to load 1.3.2 can be found on the jQTouch wiki page http://wiki.github.com/senchalabs/jQTouch/gettingstarted

                            2. Rob Chen – Posted Jan. 3, 2011

                              I had the same thing happen to me with the black screen following the example, however after receiving an email from the author, I changed line 3 to reference jqtouch/jquery.1.3.2.min.js and it worked as described. After re-reading this page, I noticed there was a Note just above this snippet of code that says to rename jqtouch/jquery.1.3.2.min.js to jqtouch/jquery.js to make this example work. Something we just over looked... Thanks again Jonathan for the great examples and walkthrus.

                            3. Andy Murray – Posted Feb. 7, 2011

                              In a comment at the end of chapter 1 you will find the following URL that give Jonathan's example files ... http://examples.oreilly.com/9780596805791/

                            4. DaveEveritt – Posted June 21, 2011

                              Stating the obvious here but - in case anyone's confused - this is just about making sure paths to files end in the literal filename. For instance, to prove that the code works with JQuery 1.4.2:

                              • put the file 'jquery-1.4.2.min.js' in a folder, at the same level as the index.html file, named 'js'
                              • set the 'src' attribute to the 'script' tag in the head to 'js/jquery-1.4.2.min.js' (which is where it is).

                              So, if you rename the jquery file 'jquery.js' and put it in a folder named 'myscripts', the path in the script tag needs to be 'myscripts/jquery.js'.

                              BTW the demo does fail with JQuery 1.6.1, so perhaps someone could pin that one down...

                              Edited on June 21, 2011, 5:49 a.m. PDT

                                View 1 comment

                                1. Kriz – Posted Aug. 6, 2010

                                  In order for this to work, you must rename the jQuery distribution in the jqtouch subdir to 'jquery.js'

                                      View 3 comments

                                      1. bronson – Posted Feb. 9, 2010

                                        The 'kilo.png' file is missing from ch04.zip, fyi

                                      2. jonathanstark – Posted Feb. 10, 2010

                                        Thanks! I'll see if I can add it in. In the meantime, you can use myCustomIcon.png from Chapter 3.

                                      3. douglerner – Posted May 1, 2010

                                        In the above icon property setting the books says this tells jQTouch where to look for the custom Web Clip icon. Can you tell us as well? :)

                                        View 11 comments

                                        1. brucemartin – Posted Jan. 27, 2010

                                          I think you mean to say "jQTouch is completely slick", not "sick". But at this point in doing the exact same code as from your examples, my iPod Simulator's screen does not show the chevron on the right side, and when I click "About" the background under "About" goes to green as it slides off to the left. The same two problems show up running in Safari also.

                                        2. brucemartin – Posted Jan. 28, 2010

                                          Here is the answer to my previous comment. Apparently the background color change to green is the standard. I am too new to JQTouch to have seen it before, and so thought it a mistake.

                                          The missing chevron can be fixed by changing the markup for the list as follows: Change: To be:

                                        3. brucemartin – Posted Jan. 28, 2010

                                          Sorry... my last comment was eaten by the HTML editor.

                                          The missing chevron can be fixed by changing the markup for the list as follows: Change: ul class="edgetoedge" To be: ul class="rounded"

                                        4. MNelson – Posted Jan. 29, 2010

                                          Thanks Bruce! Good catch.

                                        5. rickleroy – Posted Feb. 7, 2010

                                          You might even prefer changing ul class "edgetoedge" into ul class "plastic". In that case you still have the edge to edge look of the button.

                                          (BTW it seems the real problem is in the current theme.css (jqtouch provided). If you out comment (/.... /) the phrase:

                                          background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#1e1f21), to(#272729)); in: ' ul.edgetoedge li ' the arrow (chevron.png) is also shown.

                                        6. sisindri – Posted March 11, 2010

                                          Thanks for the comments...

                                        7. AneeshAbe – Posted May 19, 2010

                                          Jo, what do you think about this class issue-> edgetoedge,rounded,plastic ?

                                        8. tlc – Posted June 18, 2010

                                          Rick le Roy is right. in theme.css, ul.edgetoedge li should be changed to:

                                          ul.edgetoedge li { / background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#1e1f21), to(#272729)); / border-bottom: 2px solid #000; border-top: 1px solid #4a4b4d; font-size: 20px; margin-bottom: -1px; }

                                        9. tlc – Posted June 18, 2010

                                          in my above comment, there should be an asterisk after the first forward slash and before the second forward slash

                                        10. tomharrisonjr – Posted Aug. 8, 2010

                                          While commenting the background: -webkit-gradient directive does cause the chevron to show up, it also is probably an unintended behavior ... sometimes known as a bug :-) in JQT -- the background in ul.edgetoedge li overrides the one in ul.li arrow (the latter having the image file). I assume this is not the intended behavior. I'll mosey over there and see if I can find a proper solution.

                                        11. Maria Raffaella Pieragnoli – Posted June 27, 2011

                                          Hi! For those of you who are following step by step and who downloaded Jonathan's code, the class ul.edgetoedge li.arrow doesn't exist in themes.css You have to add these few lines at about line 406

                                          ul.edgetoedge li.arrow { background-image: url(img/chevron.png); background-position: right center; background-repeat: no-repeat; }

                                          Everything will work as expected

                                        View 2 comments

                                        1. sisindri – Posted March 11, 2010

                                          I don't see the Dates panel in the UI...

                                        2. sisindri – Posted March 11, 2010

                                          I need to have more patience... The Dates panel will show up after updating the Home panel as below.

                                        View 7 comments

                                        1. chovy – Posted Feb. 10, 2010

                                          those ids in the anchors are invalid -- ids are not allowed to start with a number.

                                        2. jonathanstark – Posted Feb. 10, 2010

                                          That was true with HTML4 and previous, but it is my understanding that HTML5 allows ids to begin with a digit. This is the validator I used:

                                          http://html5.validator.nu/

                                        3. macv – Posted March 23, 2010

                                          Everything is good when there are divs referred in href tags. But what if we have some url to point to user instead of div ? Jqtouch starts complaining that it cannot animate etc. and so request never gets completed.

                                        4. macv – Posted March 23, 2010

                                          Actually if I put link would work, but jqtouch doesnt give desired effects.

                                        5. jonathanstark – Posted April 2, 2010

                                          @mac - Not sure what you mean by "point to user" - can you elaborate?

                                        6. Dave – Posted Jan. 20, 2011

                                          My code does not slide to right. If you could repeat references to style sheet code, it would be helpful.

                                          $('#dates li a').click(function(){
                                                  var id = this.id;
                                                  RefreshEntries(id);
                                                  //navigator.notification.alert(id);
                                          
                                               });
                                          
                                        7. Dave – Posted Jan. 20, 2011

                                          The code is working. I think that using local storage to keep my id will be helpful when adding.

                                            View 2 comments

                                            1. sisindri – Posted March 11, 2010

                                              Don't forget to change the class from "edgetoedge" to "rounded" for the chevron arrows on the right of Dates panel and About panel.

                                            2. miamisoftware – Posted Aug. 4, 2010

                                              sisindri, if you ever read this, thanks a million!!!

                                                View 2 comments

                                                1. sisindri – Posted March 11, 2010

                                                  Don't forget to change the class from "edgetoedge" to "rounded" for the chevron arrows on the right side

                                                2. DaveEveritt – Posted June 21, 2011

                                                  'edgetoedge' works fine for me, YMMV.

                                                          View 4 comments

                                                          1. TPaschke – Posted May 6, 2010

                                                            Using JQuery 1.3.2 and JQTouch 1.09, the button "Save Entry" is not styled - same with the "settings" form. There must be an error in this version, because Safari tells me that it can't find the image "themes/.png".

                                                          2. TPaschke – Posted May 6, 2010

                                                            I get the same effect when i'm using Safari 4.0.5 to regard the original download sample "ch04.zip". Any ideas?

                                                          3. TPaschke – Posted May 6, 2010

                                                            Though the Safari is not styling the button, my iPod does. It's sad that the user is not able to delete his own comments...

                                                          4. DaveEveritt – Posted June 21, 2011

                                                            @TPaschke - this looks like another path issue. The css file 'theme.css' looks for images in an 'img' folder, which should be in the same folder as theme.css.

                                                            However, if it's looking for a file at 'themes/.png' it could be an error or deletion in the css file itself as '.png. is just the filename extension. So look in the css file for '/.png' (with the slash, as your browser states) and compare that line in the 'theme.css' file with a fresh download of JQTouch.

                                                                    View 2 comments

                                                                    1. tom15375 – Posted Feb. 23, 2010

                                                                      I tried this example but it doesn't work. Submitting from the Go button still doesn't remove the keyboard from the view....

                                                                    2. samholford – Posted April 15, 2010

                                                                      @ Tom set useFastTouch: false when initializing jqtouch (start of the kilo.js file). This fixes the problem for now, but it's a known issue and future versions of jqtouch will hopefully resolve this.

                                                                          View 2 comments

                                                                          1. sisindri – Posted March 12, 2010

                                                                            Fancy? Its Awesome!!!

                                                                          2. penades – Posted Nov. 16, 2010

                                                                            Its a shame the same animations do not work the same way in other devices (e.g. android)...

                                                                                  View 3 comments

                                                                                  1. Dave – Posted Jan. 20, 2011

                                                                                    I need to pass the id to the RefreshEntries function. I don't see in the code sample how this is down. Is it based on the id as a keyword

                                                                                  2. Dave – Posted Jan. 20, 2011

                                                                                    You need to point out that current code references a prior wiring. This took me a day to discover.

                                                                                    $('#dates li a').click(function(){
                                                                                        var dayOffset = this.id;
                                                                                        var date = new Date();
                                                                                        date.setDate(date.getDate() - dayOffset);
                                                                                        sessionStorage.currentDate = date.getMonth() + 1 + '/' + 
                                                                                                                     date.getDate() + '/' + 
                                                                                                                     date.getFullYear();
                                                                                         });
                                                                                    
                                                                                  3. Dave – Posted Jan. 20, 2011

                                                                                    I want to intercept the id and pass the id to RefreshEntries function.

                                                                                    Do I need to store the id in localstorage or can I call the function on the click event?

                                                                                  View 3 comments

                                                                                  1. davegroff – Posted Feb. 4, 2010

                                                                                    JQ newbies like me would be looking here for a mini-tutorial on how to customized JQTouch. thanks! (Love this format for book publishing!)

                                                                                  2. ksahnine – Posted Feb. 16, 2010

                                                                                    The property that triggers a slide left animation is "slideSelector" and not "slideInSelector".

                                                                                  3. jonathanstark – Posted Feb. 17, 2010

                                                                                    @kadda - Great catch! I'll add it as errata on the book page and eventually it'll trickle it's way through the system.

                                                                                  View 1 comment

                                                                                  1. redware – Posted April 4, 2010

                                                                                    I am using some freeware called IBBDEMO4 from blackbaud labs on a PC to show this great stuff you have here. Not sure whether chapter 3 worked but chapter 4 with jqtouch is working fine.

                                                                                      View 1 comment

                                                                                      1. douglerner – Posted May 1, 2010

                                                                                        Just a general comment. While I am finding this book fascinating and chock full of information, the author seems to put things out of an easy-to-follow order. Like after adding the dates div above he shows the result of what that panel should look like. But if you enter the web app at that point there is no way of actually getting to it.

                                                                                        After looking and looking through the code and not finding a mistake I decided to go on. Sure enough in the NEXT section he has us add a UI to the home div that will take us to dates.

                                                                                        Things like that seem to occur frequently. I would just like to suggest maybe editing a bit so readers "have all the pieces" at the right time. Thanks.

                                                                                        View 4 comments

                                                                                        1. tlc – Posted June 18, 2010

                                                                                          To get the rounded corners to work: should be

                                                                                        2. tlc – Posted June 18, 2010

                                                                                          arhg, my code got deleted. You have to add the rounded class to the ul.

                                                                                        3. Yuanga – Posted Aug. 10, 2010

                                                                                          ul class="rounded">

                                                                                        4. Andy Murray – Posted Feb. 7, 2011

                                                                                          didn't work for me :(

                                                                                            View 2 comments

                                                                                            1. douglerner – Posted May 1, 2010

                                                                                              This is getting quite cool!

                                                                                            2. Rick Faircloth – Posted May 8, 2011

                                                                                              I'm working through this tutorial, viewing the design on desktop Safari (set to mobile) and also on my Samsung Fascinate (Android, of course).

                                                                                              Up to this point, the design and functionality have essentially been the same as with the iPhone. However, at this point, the "flip" animation on the Fascinate is simple a cross fade.

                                                                                              Is this to be expected?

                                                                                              Thanks for a great tutorial and intro do iPhone/mobile design!

                                                                                              Rick