Contact Me

@zoltandulac

Categories

Archives

Cross-Browser Animated CSS Transforms — Even in IE.

April 5th, 2010 by zoltan · 11 Comments

Cross-Browser Animated CSS Clock Example based on an original WebKit example by Toby Pitman. Click image above to view.

In my first article about CSS3, I introduced a new script, cssSandpaper, which allows developers to sidestep the myriad of vendor specific properties and just use one property to implement properties like transform for all browsers, including IE.

After posting the article, I saw many examples of CSS3 Transform using animations. Toby Pitman’s Old School Clock is an excellent example of how one can use a Webkit’s -webkit-transform to make a small but excellent demo. I wanted to prove that it would be easy to take this example and make it work in all modern browsers, so I did. It took 15 minutes (okay, I had to change cssSandpaper to offer scripting support, but that didn’t take too long either). I then coded a few more examples to show that some really neat things can be done using a small bit of JavaScript.  Here are links to these examples:

How To Do CSS3 Animated Effects?

If this was the perfect world, all a developer would need to do is use a DOM element’s style property and manipulate the appropriate camel-case CSS property. For example, if a developer wanted to script the rotation of a node, he or she would code the following:

    node.style.transform = "rotate(25deg)";

However, this is not the perfect world — after all, I am not making millions writing this blog and the current flavours of IE in use today don’t support many of the CSS3 properties. However, using cssSandpaper, one could use the following method to do the same thing:

    cssSandpaper.setTransform(node, "rotate(25deg)");

Developers can use cssSandpaper to manipulate opacity, box-shadow, and background gradients, using cssSandpaper.setOpacity(), cssSandpaper.setBoxShadow() and cssSandpaper.setGradient() respectively. All these functions take two parameters: a DOM node, and the appropriate CSS property values as described in the cssSandpaper documentation. For example:

    cssSandpaper.setTransform(node, "rotate(25deg) scale(2, 2) skew(20deg, 20deg)");
    cssSandpaper.setOpacity(node, 0.3);
    cssSandpaper.setBoxShadow(node, "10px 10px 5px #ffcccc");
    cssSandpaper.setGradient(node, "-sand-gradient(linear, center top, center bottom, from(#0000ff), to(#ff0000));")

For more information, please read the official documentation of cssSandpaper.

Caveats

  • When animating using transform‘s scale() function, make sure you avoid scaling objects too much larger than their original size. This is due to the fact that IE scales objects as if they were images, and scaling-up an object will make the result quite pixelated.
  • The -sand-gradient() function does not use Firefox’s native -moz-gradient function to produce CSS3 gradients, but a solution using Canvas which works in all Canvas enabled versions of Firefox. I will update cssSandpaper to use -moz-gradient in a future release (if anyone wants to help me get this working, please contact me via the email address at the top of this page, or by leaving a comment below).

Go to the cssSandpaper documentation to download the latest version.

Tags: CSS · CSS3 · JavaScript · Uncategorized · ,

11 responses so far ↓
  • 1 Cross-Browser Animated CSS Transforms ? Even in IE. | CSS Guru How to CSS // Apr 6, 2010 at 3:58 pm

    [...] is the original post: Cross-Browser Animated CSS Transforms ? Even in IE. Share and [...]

  • 2 CSS3 transform are coming in a browser near you (even in IE) « Position Absolute, resources for the web developer // Apr 6, 2010 at 3:58 pm

    [...] nice project, cssSandpaper is a js animation framework making the use of CSS3 transform [...]

  • 3 links for 2010-04-07 // Apr 7, 2010 at 1:14 pm

    [...] Cross-Browser Animated CSS Transforms ? Even in IE. (tags: css3 transform ie webdesign) Socio-Encapsule this: [...]

  • 4 Weston Ruter // Apr 12, 2010 at 2:43 pm

    Good idea prefixing your CSS properties/values with your own -sand-* instead of looking for existing vendor-prefixed ones; that way you are in control of their syntax and semantics.

  • 5 Anonymous // Apr 26, 2010 at 12:51 pm

    [...] suosittelen lukemaan artikkelin Cross-Browser Animated CSS Transforms ? Even in IE, jonka on kirjoittanut Zoltan ?Du Lac? Hawryluk. H

  • 6 CSS3 Transitions – Are We There Yet? | samuli.hakoniemi.net // Apr 26, 2010 at 12:52 pm

    [...] I recommend reading an article titled Cross-Browser Animated CSS Transforms ? Even in IE, written by Zoltan ?Du Lac? Hawryluk who is the author of [...]

  • 7 Anonymous // May 5, 2010 at 5:08 am

    really nice work! could you plz fix cssSandpaper.setGradient for colors with alpha values (ie needs #aarrggbb, all the others use rgba(rrr, ggg, bbb, aaa))

  • 8 zoltan // May 5, 2010 at 9:13 am

    @anonymous: this is a great idea and something I am currently looking into. I will be posting in the next few days a roadmap of what I plan to put into cssSandpaper with an open request to the web development community for feedback and feature requests. I am glad people are using it for their project and want to make it as painless to use as possible.

  • 9 Fandekasp // May 5, 2010 at 9:05 pm

    Great project, I’ll follow it very carefully

  • 10 zoltan // May 10, 2010 at 1:34 pm

    @anonymous: I have added rgba() support in the latest release of cssSandpaper. See my blog post about cssSandpaper with rgba() gradient and transform: translate support

  • 11 CSS Three — Connecting The Dots - Smashing Magazine // May 27, 2010 at 6:32 am

    [...] of CSS3 in the WildShowcase of sites using CSS3 properties.CSS3 Transitions – Are We There Yet?Cross-Browser Animated CSS Transforms — Even in IE.Related ArticlesYou may be interested in the following related posts:CSS3 Solutions for Internet [...]

Give Feedback

Don't be shy! Give feedback and join the discussion.