Placed in: Home arrow Programming arrow Webdesign arrow The iPhone Contacts App with CSS and jQuery
The iPhone Contacts App with CSS and jQuery

Remember that I created "the iPhone unlock screen" and "the iPhone springboard" in xHTML, CSS and jQuery? Today, I'm bringing you another chapter of transferring some of the beautiful iPhone layouts to the webbrowser.

The design of the Contacts app will be used and displayed in your browser. Funny fact is that this is the first "iPhone to CSS/jQuery conversion" that I created (before the unlock and springboard screen). I'll try to give you the real iPhone feeling with these tutorials.

iPhone Contacts App with CSS and jQuery

OK, maybe not fully the "feeling" (look and feel) from the iPhone, since I can't make any webbrowser react to placing your finger on the screen, but your mouse will do the trick.

Demo Scrolling box - iPhone contacts style   Download Scrolling box - iPhone contacts style

Features:

  • XHTML and CSS valid.
  • "Top indicator" changes character while scrolling (Just like the iPhone).
  • Including "Search" on the right (Just like the iPhone).
  • Pretty sleek interface, including see-through elements (Just like the iPhone).
  • Falls back nicely when the user has JavaScript disabled.
  • Combined with the unlock and springboard screen, it looks like the real deal.
  • Tested and working on Firefox 3, Internet Explorer 7 (With fixes) and Safari 3.

Known issues

  • The "top indicator" doesn't always show the correct character, especially when using the search.
  • The "top indicator" is placed on top of the scrollbar of the browser.
  • I wrote some pretty damn ugly JavaScript (Hey, it works).
  • Works crappy on an actual iPhone.
  • Only works correct when browser doesn't scroll. For people with a small screen resolution, here's a smaller demo (I just changed the CSS and images to 50% of the original size).

Other than those minor issues, it works as expected. Make sure you check it out!

So you want to know how I created that page?

XHTML

Here's a part of the HTML of the page:

 
<div id="iphone-scrollcontainer">
   <ul id="iphone-search">
       <li><a href="#A" title="A">A</a></li>
        <li><a href="#B" title="B">B</a></li>
        <li><a href="#C" title="C">C</a></li>
        <li><a href="#D" title="D">D</a></li>
        <li><a href="#E" title="E">E</a></li>
        <!-- More characters here -->
    </ul>
   <ul id="iphone-scroll">
      <li>
        <div id="nav-indicator-fixed"></div>
        <a name="A"></a>
      <div class="nav-indicator" id="nav-a">A</div>
         <ul>
            <li><a href="http://en.wikipedia.org/wiki/Amsterdam" title="Amsterdam"><strong>Amsterdam</strong>747,290</a></li>
            <li><a href="http://en.wikipedia.org/wiki/Arnhem" title="Arnhem"><strong>Arnhem</strong>144,101</a></li>
            <!-- More info here -->
         </ul>
      </li>
      <li>
        <a name="B"></a>
      <div class="nav-indicator" id="nav-b">B</div>
         <ul>
            <li><a href="http://en.wikipedia.org/wiki/Bolsward" title="Bolsward"><strong>Bolsward</strong>9,607</a></li>
            <li><a href="http://en.wikipedia.org/wiki/Buren" title="Buren"><strong>Buren</strong>25,644</a></li>
            <!-- More info here -->
         </ul>   
      </li>
   </ul>
</div>

Here's some information about the nodes:

  • #iphone-search - This is the "search-bar" on the right side of the iPhone, displaying characters for a fast lookup. This works with HTML anchors for when users have JavaScript disabled.
  • #nav-indicator-fixed - The navigation indicator is used to display the current character where the user is when scrolling, just like the real iPhone. The div is empty since we'll use JavaScript to display the current character.
  • #nav-indicator - This is the place with the seperator displaying the character.

Those were the most important parts. Everything else should be pretty straightforward.

CSS

This page wouldn't look really pretty without the power of CSS. I also used the iPhone layout created by Tehan+Lax.

 
#iphone-scrollcontainer { height:461px; width:320px; overflow:auto; position:absolute; top:140px; left:40px; }
#iphone-scroll { list-style: none; padding:0; margin:0; font-family:Georgia, Times, serif; font-size:15px; }
#iphone-scroll li {  }
#iphone-scroll ul { list-style: none; padding:0; margin:0; }
#iphone-scroll ul li {  }
#iphone-scroll ul li a { display:block; text-decoration:none; color:#000000; background-color:#FFFFFF; line-height:30px;
  border-bottom-style:solid; border-bottom-width:1px; border-bottom-color:#CCCCCC; padding-left:10px; cursor:pointer; }
#iphone-scroll ul li a:hover { color:#FFFFFF; background-image:url(../images/hover.png); background-repeat:repeat-x; }
#iphone-scroll ul li a strong { margin-right:10px; }
 
.nav-indicator { line-height:20px; background-image:url(../images/nav-indicator-bg.png); background-repeat:repeat-x; color:#FFFFFF; text-indent:20px; }
 
#nav-indicator-fixed { line-height:20px; background-image:url(../images/nav-indicator-bg.png); background-repeat:repeat-x; color:#FFFFFF; text-indent:20px;
position:fixed; width:320px; }
 
#iphone-search { list-style: none; padding:0 5px; margin:0; font-family:Georgia, Times, serif; font-size:12px; line-height:17px; left:315px; margin-top: 20px;
position:fixed; text-align:center; font-weight:bold; }
#iphone-search li a { text-decoration:none; color:#666666; }
#iphone-search li a:hover { color:#000000; }
.searchbg { background-color:#999999; }

Nothing really fancy going on over here: Just some CSS styling as it should be. Only some notes:

  • #iphone-search - is placed on a fixed position (this is the reason that this doesn't work correctly when the user is resizing is browser).
  • #iphone-scroll ul li a - is displayed as a block element to make the hover-effect work and still be HTML-valid.

JavaScript

Now this is the real fun part. Although there are already comments added to the source, I still want to explain some of the most important part of the code here.

 
$(document).ready(function()
{
   // First time, the indicator needs a character
   $("#nav-indicator-fixed").append("A");
   
   // Fading out the search bar
   $("#iphone-search").fadeTo(1, 0.85);
   
   // Append background when search bar is hovered
   $("#iphone-search").hover(function() {
      $("#iphone-search").addClass("searchbg");
   },function() {
      $("#iphone-search").removeClass("searchbg");
   });
   
   // When scrolling, this function checks if the indicator needs to be changed
   var curb = $("#nav-b").position().top;
 
   var changeNavIndicator = function(value) {
      $("#nav-indicator-fixed").replaceWith("<div id=\"nav-indicator-fixed\">"+value+"</div>");
   }
 
   $("#iphone-scrollcontainer").scroll(function()
   {
      if($("#nav-b").position().top < 20 && $("#nav-b").position().top > -20) {
         if(curb < $("#nav-b").position().top) {
            changeNavIndicator("A");
         } else {
            changeNavIndicator("B");
         }
         curb = $("#nav-b").position().top;
      }
   }
   
   // Fade the indicator, staying CSS2.1 valid
   $("#nav-indicator-fixed").fadeTo(1, 0.85);
}

I think most of the things are made already really clear.

  • $("#iphone-scrollcontainer").scroll( - The function that's called when the user starts scrolling. This is the moment when jQuery keeps on checking if it passed a bar and if it needs to change the nav indicator (calling that function).
  • $("#iphone-search").hover( - When the user is hovering over the search-bar, jQuery will append a class to it to add a background colour. When the user is not hovering anymore, the class is removed.
  • var curb = $("#nav-b").position().top; - The position from a certain navigator is stored in a variable to be used later when the user is scrolling past it.
  • if($("#nav-b").position().top < 20 && $("#nav-b").position().top > -20) { - This statement checks if the user is scrolling up or down and checks which character should be displayed in the navigator bar.

Conclusion and download

If you view the JavaScript file, you'll see it's pretty dirty code. If you want to refactor it, be my guest! There are also some minor downsides to this screen, but other than that, it's working pretty nice. What do you think about it?

Demo Scrolling box - iPhone contacts style   Download Scrolling box - iPhone contacts style

That's it! Hoped you learned something new today and start loving the jQuery framework (like I do). Be prepared to expect more jQuery / CSS / xHTML iPhone UI articles in the future. Make sure to subscribe to receive the latest updates. Do you think you would be able to use this somewhere? Or do you see some errors that should be fixed?


Tags:  iphone mac screen jquery xhtml css

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
Comments
Add NewSearchRSS
secure weightloss pill - secure weightloss pill   2011-06-10 04:28:15
Gravatar image This was really a great site which I had found it to be very cordial and I really liked it very much. Thanks a lot.
safe pharmacy online - safe pharmacy online   2011-06-10 04:28:53
Gravatar image The information which I had found in this blog was really very cordial and I had liked it very much. Thanks a lot for the information.
clinic pharmacy info - clinic pharmacy info   2011-06-10 04:29:30
Gravatar image This site was really very interesting and I had got impressed with this stuff. Thanks a lot for the lovely information which was given in this blog.
hot birth control pills - hot birth control pills   2011-06-10 04:30:06
Gravatar image I had really enjoyed viewing this blog. The information was really very cordial and it was very helpful for me. Thanks a lot for the stuff.
best deals pharmacy reviews - best deals pharmacy reviews   2011-06-10 04:30:45
Gravatar image I am very glad to post a comment on your blog as I really enjoyed reading your posts.
diabetes pills info - diabetes pills info   2011-06-10 04:32:33
Gravatar image The information provided was extremely useful and informative. Thanks a lot for useful stuff.
secure fat loss pills - secure fat loss pills   2011-06-10 04:33:42
Gravatar image This article is so interesting I am completely engrossed. Really I appreciate the efforts you take for making these posts. Thanks for sharing with us such useful information.
online anti smoking pills revi - online anti smoking pills reviews   2011-06-10 04:34:38
Gravatar image I really enjoy reading your well written articles. I think you spend numerous effort and time in posting the blog. I have bookmarked it and I am looking ahead to reading new articles. Keep up the good articles!
best pharmacy information - best pharmacy information   2011-06-10 04:35:12
Gravatar image You are awesome people and bring great info; I definitely look forward for your work as I am a regular visitor of your site. Thanks a lot, superb work!!!!!
birth control pills center - birth control pills center   2011-06-10 04:35:49
Gravatar image I am strongly associated with this site. As this site has inspired me a lot always in a new way and made my work easy by every time highlighting on the new issue and make me pleased. Thanks you people rock!!!!!!
discount birth control pills - discount birth control pills   2011-06-10 04:36:24
Gravatar image I am frequent reader of the articles and new knowledgeable post about new things always and would be searching new stuff for that. And I really thank you people for providing us new articles and post. Thanks a lot!
hair lack side effects reviews - hair lack side effects reviews   2011-06-10 04:36:56
Gravatar image It was really surprising to see such a wonderful post that is inspiring and informative and caught the attention of many people. I am a regular visitor of the blog and love the work of these people.
hair hair loss side effects hu - hair hair loss side effects hub   2011-06-10 04:38:02
Gravatar image This is a wonderful website that has great info and is helpful for one and all. I always look forward for your website to gather any kind of information. Hope you people do like this only wonderful job. Cheers
overweight pill - overweight pill   2011-06-10 04:41:10
Gravatar image I often like surfing on net and find info on new things and this time I got a new website which has great info and is quite brilliantly written. Am just thrilled and excited to see this and hope to see more work of you people in future.
best deals pharmacy online - best deals pharmacy online   2011-06-10 04:41:54
Gravatar image You guys are really wonderful who search and bring such a wonderful info, I am glad to see this time also a useful stuff that had inspired me. Thanks a lot do keep giving us genuine stuff
Sam Sehnert - Try this plugin   2012-03-01 07:36:32
Gravatar image Try the jquery list plugin to this
Sam Sehnert - re: Try this plugin   2012-03-01 07:38:24
Gravatar image
Sam Sehnert wrote:
Try the jquery list plugin to this


Wow... totally killed my post!! What I was trying to say was:

Try add this plugin to your demo: https://github.com/teamdf/jquery-list. It adds the same floating headings as the iOS contacts app has.
takeyourjerseys - take your jerseys   2012-05-25 07:38:46
Gravatar image New Jersey Devils were established in 1982. Their head coach is Jacques Lemaire and their captain is in vacant. The arena is Prudential Center in Newark. New Jersey Devils Jersey are owned by Jeffrey Vanderbeek, who bought them in 2004 for $125 mil and now they are worthy $218 mil. The colors of the New Jersey Devils Jersey are red, black and white. We provide the top quality NHL Jersey in lower price. Show your support to New Jersey Devils Jersey with this gorgeous jersey."
NHL New Jersey Devils #15 Jamie Langenbrunner CCM Red and Green n
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

Subscribe to Marcofolio