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: iPhone, Safari, CSS Visual Effects, graphics, 3D
November 7th, 2008 at 4:00 am
[...] has a blog entry with a video showing off a mobile Safari demo of using Apple’s CSS Visual Effects to create a [...]
November 7th, 2008 at 7:42 am
is it me or something wrong with the script?
the demo of 3d coverflow does not work in firefox 2?
November 7th, 2008 at 7:51 am
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.
November 7th, 2008 at 9:00 am
[...] on his personal blog inside looking out, Ying posted an entry detailing his CoverFlow (zflow) demo, one part of his new open source [...]
November 7th, 2008 at 9:13 am
@omtv: RTFA
nice demo, thanks. project looks very interesting.
November 7th, 2008 at 9:22 am
[...] on his personal blog inside looking out, Ying posted an entry detailing his CoverFlow (zflow) demo, one part of his new open source [...]
November 7th, 2008 at 1:29 pm
Nice work. Although it comes across as a bit quirky on the real device - still, a good start. :)
November 7th, 2008 at 2:03 pm
[...] 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 [...]
November 8th, 2008 at 4:37 am
[...] a blog entry with a video showing off a mobile Safari demo of using Apple’s CSS Visual Effects to create a [...]
November 9th, 2008 at 11:10 pm
@Samuel Hallé: The zflow.js does not require jQuery anymore (although the example file still does… for now)
November 11th, 2008 at 3:14 am
[...] 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 [...]
November 13th, 2008 at 9:16 pm
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.
November 23rd, 2008 at 10:40 am
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
December 2nd, 2008 at 1:47 am
[...] twist - a physical keyboard and Flash + video support. Apple’s mobile web efforts have promise, but people sure do ask for [...]
December 16th, 2008 at 11:34 pm
Hi, i was wondering if anyone modded this to allow image captions? If not how could it be done? thanks in advance.
December 17th, 2008 at 3:03 pm
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.
December 22nd, 2008 at 1:08 am
[...] 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) [...]
December 30th, 2008 at 8:57 pm
[...] - Hardware accelerated 3D Web graphics with CSS Visual Effects. The specs exist, they’re implemented on iPhone, and definitely coming to [...]