Building CoverFlow for Safari on iPhone

Did you know that 3D graphics and animation is possible with Safari on iPhone?

If you have an iPhone, try out the CoverFlow (zflow) demo live with a live Flickr feed.

This CoverFlow demo is part of a new open source project I’ve started, CSS-VFX. The idea with CSS-VFX is to demonstrate all the cool things that are possible with Apple’s CSS Visual Effects extensions.

How does it work?

The zflow demo in CSS-VFX uses the Apple CSS Visual Effects extensions for hardware accelerated (on iPhone!) 3D perspective correct transforms and easily animated transitions. HTML 5 Canvas is used for simulating reflections.

  • zflow starts by loading each image from the images array. When each image is loaded, we scale the image to fit in a square region, and apply 3D CSS transforms to scale it in place.
  • Reflections - zflow then takes the scaled image and creates a Canvas element that contains a gradient alpha mask of the image’s reflection (using a “reflect” function to do this) and positions the canvas element in place.
  • Touch Controller - zflow creates a TouchController object, who’s job is to field touch events from Mobile Safari and calculate an appropriate offset.
  • Clicking - zflow detects when no move events have been made, and zooms + rotates the focused image forward by setting a “CSS Transition”ed 3D transform on the focused image. Clicking again transitions the image back.
  • Inertia - zflow achieves inertia by setting the “transition timing function” of the “tray” to an “ease-out” function, which slows things down. On the touch end event, we calculate the projected velocity and set the tray’s target position to that location. CSS Transitions handles the decay in velocity as the transition timing function executes — slowing the tray down gradually.

What’s next?

I hope that CSS-VFX can become a series of graphics gems that clearly illustrate how to use CSS Visual Effects, as well as talk about some of the corner cases and best practices to get the best performance. If you come up with something you’d like to include, please let me know. I’ll be tinkering with a few more gems myself, just watch the project for more as time goes on.

And tell a friend, I can’t wait to see what everyone else does with these great new features in Safari on iPhone.

Where to learn more

The CSS-VFX open source project is a good place to start. You can just use the zflow code in your own iPhone web pages (there’s docs on how to do that); and deep dive into the innerworkings of zflow to understand what exactly is going on.

Also, check out Apple’s proposed extensions: CSS 3D Transforms, CSS Transitions, and CSS Animation. They provide full specifications on what’s possible. Of course, there are a few gotchas when using these in practice, and I hope to document these as things progress.

Technorati Tags: , , , ,

18 Responses to “Building CoverFlow for Safari on iPhone”

  1. Ajaxian » CSS-VFX: CSS Visual Effects Tutorials and Components Says:

    [...] has a blog entry with a video showing off a mobile Safari demo of using Apple’s CSS Visual Effects to create a [...]

  2. omtv Says:

    is it me or something wrong with the script?
    the demo of 3d coverflow does not work in firefox 2?

  3. Samuel Hallé Says:

    Nicely done! Great to see improvement in iPhone web development.

    One comment though, using jQuery on an iPhone application may be a little bit of overkill.. Especially for a little bunch of code like that. A lot of iPhone users are on Edge and 25+kb takes a lot of time to download.

  4. CoverFlow in Safari for iPhone: Proof of Concept With Promise | TheAppleBlog Says:

    [...] on his personal blog inside looking out, Ying posted an entry detailing his CoverFlow (zflow) demo, one part of his new open source [...]

  5. dave Says:

    @omtv: RTFA

    nice demo, thanks. project looks very interesting.

  6. CoverFlow in Safari for iPhone: Proof of Concept With Promise | Gadget News and Reviews Says:

    [...] on his personal blog inside looking out, Ying posted an entry detailing his CoverFlow (zflow) demo, one part of his new open source [...]

  7. James Urquhart Says:

    Nice work. Although it comes across as a bit quirky on the real device - still, a good start. :)

  8. CoverFlow in Safari for iPhone | MirthLab Says:

    [...] If you’re new here, you may want to subscribe to my RSS feed or follow me on Twitter. Thanks for visiting!This is a really interesting proof of concept: Building CoverFlow for Safari on iPhone [...]

  9. CSS-VFX: CSS Visual Effects Tutorials and Components - Video Says:

    [...] a blog entry with a video showing off a mobile Safari demo of using Apple’s CSS Visual Effects to create a [...]

  10. Charles Ying Says:

    @Samuel Hallé: The zflow.js does not require jQuery anymore (although the example file still does… for now)

  11. Entwickler: Konferenz-Videos, Cover-Flow und Programmier-Ansätze Says:

    [...] interessante Links für iPhone-Entwickler: TAB macht auf eine Web-basierte Möglichkeit aufmerksam, Cover-Flow Effekte mit Apple’s Visual Effects CSS-Extensions zu generieren. Dieses Video (Youtube-Link) gibt einen [...]

  12. Brente Says:

    Excellent work. I saw the GoogleCode page, but there is no download .zip or anything. Could you post a simple downloadable version of it with a local array of images? That would be helpful for people to see a realistic implementation and usage.

    Also it would be cool to add easy configurations to allow the touch/flip/zoom feature to just zoom and not reverse or do nothing if needed.

    Thank you. Great stuff.

  13. Brente Says:

    Hello All -

    I have modified Charles’s original Coverflow to remove Jquery, Flickr and made the images a local static array. Check it out (.ZIP) and help make this CSS FX even better at:
    http://groups.google.com/group/css-vfx

    Cheers, brente

    Modifications:

    deleted jquery js link - no calls to it anymore
    deleted flickr image feed function - not needed for static example
    deleted window.setTimeout func - apple meta tags replace this functionality

    changed jquery functions to getElementById().className - eliminates jquery

    added id “container” to the main div - used for orient change identifier
    added local image array function - requested feature for static version
    added onload init function - replaces jquery onload
    added 5 demo images - replaces flickr image feed
    added metatags for web apps - apples enhancement that hides url bar for web apps
    added xhtml 1.0 strict doctype

  14. inside looking out » Blog Archive » Nokia Finally Answers the iPhone Says:

    [...] twist - a physical keyboard and Flash + video support. Apple’s mobile web efforts have promise, but people sure do ask for [...]

  15. mark Says:

    Hi, i was wondering if anyone modded this to allow image captions? If not how could it be done? thanks in advance.

  16. cameron Says:

    Yes! Can anyone help with captions? With my limited js experience I’ve attemped to add caption functionality but have hit a wall. If anyone is interested I can go into more detail, although it may not help because I do not have a functioning solution.

  17. links for 2008-12-22 :: User First Web Says:

    [...] inside looking out » Blog Archive » Building CoverFlow for Safari on iPhone Nice demonstration of Mobile Safari css effects used to make a smooth cover flow effect. (tags: css iphone mobile safari javascript coverflow) [...]

  18. satine.org » Macworld 2009 Predictions Says:

    [...] - Hardware accelerated 3D Web graphics with CSS Visual Effects. The specs exist, they’re implemented on iPhone, and definitely coming to [...]

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word