CSS3 Feedback: Animated Shapes

Published 11 years, 1 month ago











  1. Thing is, CSS animation is not stepping on the toes of JavaScript. As far as the purist standpoint goes, CSS is entirely devoted to the presentation of elements. JavaScript is about user interaction behaviour and HTML manipulation. Animating is (most often) merely triggered by a behaviour, but animation itself is entirely within the remit of “controlling presentation” and therefore belongs in CSS.

    Irregular objects would be nice, certainly, but I’ve got bigger concerns with CSS. Sorting out layout is desperately needed, most of the other stuff that CSS3 has on the agenda is nice to have, but far less pressing. Rounded corners, drop shadows, animation – nice. But not critical.

  2. Matt, while not trying to derail Eric’s point too much (since he wanted to avoid it to begin with), JavaScript is not just about user interaction or HTML manipulation. It’s about “change”. My concern with CSS animation has been that a change is being performed and it’s not entirely clear how that affects JavaScript’s ability to detect and work with that change. What is the computed style of an element half way through an animation? Does JavaScript know when the animation has started or when it’s stopped? Is it easy to bind and unbind animations? (And I haven’t had time to properly research the matter).

    In any case, I agree with Eric Meyer on this post and (as I tweeted), I’m now thinking through the spec for element-shape (I’m already finding it harder than I expected).

  3. The “contour” idea is the way to go for both floats and box envelopes IMO. This is the kind of work computers are good at—let them do it. Let us just draw the polygon and get on with it.

    The question of how to deal with faded gradients isn’t hard to answer: masks. In fact, masks might be the right way to handle all contours: a simple B&W shape defining the borders.

  4. Fair point, I’ll keep my reply brief so as to not get too far off topic (my apologies Eric). As I understand it, and I am by no means knowledgeable about the intricacies of browser functionality or mechanics, the JavaScript layer can inspect the properties of any element at any point in time. That’s the behaviour of web sites today, the caveat being that all state changes (bar :hover and it’s siblings) have been implemented in JavaScript. I would therefore expect that JavaScript would be able to see all the information about an object no matter what point in the animation it is in, even in a CSS powered animation. Whether that’s the case right now isn’t the point I was attempting to make, though it is certainly one that needs clarifying and I’m glad you pointed it out as I was taking it for granted. From an ideological perspective, animation fits into CSS. Whether the practical implications of that fit or not is a different matter.

    Getting back on topic, I do not understand the desire to define non-rectangular shapes programatically. As mentioned by Eric and yourself, it gets very complicated very quickly, and hard to manage for the author. Perhaps I am not understanding quite what the use case is for this sort of ability – but wouldn’t CSS Masks achieve these sort of things far more easily? Apply an image mask to a content area and you have your irregular shape.


  5. Matt, CSS masks might be fine, assuming some clarification. You’ll need specify what happens if, for example, a 5×5 pixel mask image is applied to a div containing several paragraphs of text in order to define the actual area of the div where that paragraphed content is allowed to flow. Similarly, we’d need to know what happens when such a mask is applied to a floated 300×300 image with text flowing next to it. Also what happens when a mask image is bigger (whether by a little or a lot) than the element to which it’s applied, in both the replaced and non-replaced cases.

  6. As I understand it the mask can be made to grows/shrink to fit the content area using a nine-slice approach:

    “One key difference between mask-box-image and its border-image counterpart is that it doesn”t attempt to fit itself to border widths. It will just render the corners unscaled and tile/stretch itself into the border box without regard for the border itself. This lets you easily use nine-piece-image effects as masks on elements without borders (often image or video elements).”

    I assume that the other methods do not scale, though it’d be nice to have an option to control that. I also love the fact the CSS Mask takes SVG (which I presume does scale, but I’ve not tested.

    Definitely there needs to be some clarification, for example I’d like to see a property to switch between treating the clipped area’s bounding-box as the float boundry, and the actual edge of the mask as the float boundry; so the author has the choice of allowing text to wrap to either the bounding box or the mask edges itself.

    Either way I look at it, I find the concept of using an image to define a non-regular shape as easier to understand, easier to maintain, and more flexible than any kind of co-ordinate based system.

  7. […] Meyer provides feedback on some long awaited CSS3 features. It will be very cool to use shapes in […]

  8. Funny how the form inputs got almost no mention, specially considering how html5 will bring a LOT of different inputs into the game.

    The calendar inputs (date, month, datetime…) will NOT be used by the large mass of designers unless they are able to style them and get them to look fancy enough.

  9. > … coolness of slowly rotating an entire page. Which I totally need to do the next time I give a presentation.

    Give a presentation on a boat in stormy weather and have what’s on your screen stay leveled with the horizon :-)

  10. I’m not completely against CSS animations but I’m definitely afraid of it. I hope that “turn off CSS animations” browser option will come hand in hand with CSS animation implementations.

  11. I don’t know that I agree with your assertion, Daniele, that “calendar inputs (date, month, datetime…) will NOT be used by the large mass of designers unless they are able to style them and get them to look fancy enough”. All the existing form inputs are used by, well, just about everybody, even though it’s quite possible to construct JS-based equivalents that can be fully styled. I think a good number of people will just drop in calendar inputs once they’re widely supported, so that they can reduce page weight and stop having to worry about all the JS and stuff that goes into calendar inputs now.

    Of course, a lot of people will stick with what they’re already using. In that sense, I suppose, calendar inputs will face the same problem JS alternatives to existing form elements do: overcoming the inertia of what’s already in place.

  12. Matt, the nine-slice approach is fine for what it does but not nearly enough to manage what a lot of people want. For example, say I want to put three paragraphs of text in a diamond shape. So I wrap them in a div and apply a mask to that div. All I have is a 20×20 PNG mask image. The nine-slice approach means I get cropped corners, but no diamond flow. A scaling approach means… what? Assume the rendered size of the div is 500×500, if that helps.

    Saying “don’t do that” doesn’t fly, of course: someone will and the browser has to know what to do. So that has to be specced out.

    I’m not opposed to your suggestion, mind you. I think masks are a nicely intuitive and powerful way of handling shapes, even if they do increase page weight in a way that a coordinate-based shape generally wouldn’t (though in some cases, like very curvy shapes, that might not be true). But we can’t simply say “masks are the way!” and expect it to Just Work. Someone has to work through all the ramifications and then—and this is always the tricky part—get the WG to consider it seriously and the implementors to get behind the idea of implementing it. Or do it the other way around, by getting implementors behind the basic idea and then speccing it out in a universally acceptable manner so that the WG can just publish and approve the result.

  13. Sorry about that, but being italian I face a market where looks is king (“king-er” than content) from the customer perspective, and it’s going to be tough to say “here’s an upgrade to your site, with calendar inputs!” “but we already had those and they looked better”.

    Explaining them that those are less mantainable is going to be a pain in the arse. Having pseudoclasses to style webforms inputs would be a very nice addition, say input[type=url]:icon{ url(/i/webicon.png) } for url items, and more complex ones for the calendar widget.

    Altering colors, sizes, (single) borders/backgrounds would be enough for pretty much anyone.

  14. There are definitely scaling issues when using an image-map as a mask. I’m not convinced that many authors would use a 20×20 image and expect it to work at 500×500, but as you say – it needs to be thought about. “How would I break it” interrogation like that is to be expected, and sensible answers must be given in the spec.

    What I like about the Mask option is the ability to use SVG for scalable shapes, and also bitmaps for cases where the scale of the masked area is more rigorously known (which for the use cases I have in mind would almost always be the case anyway). It’s the best of both worlds – a vector/co-ordinate based mask capability alongside a less involved bitmap alternative.

    As for page weight, that is and isn’t a concern depending on all sorts of things. At the moment Webkit expects a transparent PNG, which is 32bit, and therefore bloats the file-size fast. I filed a bug-report some months ago arguing for a change to use the luminosity value of any image as the alpha value of the mask – this way instead of a 200kb 32bit PNG you could use a 60kb JPG. Or a GIF.

    I’m encouraged by the fact that Webkit already has an implementation of Masks working. I’d like to see a few changes, as we have discussed, but I see the thought process going on over there that would mean Masks have a credible chance of offering a solution to non-regular shapes in CSS that are flexible and un-complicated for an author to implement. I appreciate that it may be a lot harder for browser engineers, but frankly that isn’t my concern.

    Also on my wish list (no matter how implausable) is that ability for CSS to interrogate connection speed and browser states. So I can set a default “low quality” version but serve a “high quality” version if the connetion speed is above a designated rate. Or detect cases where images are off but CSS is on.

    @connection all and (min-speed: 512kbps) { body { background-image: url(high-quality.png); } }

Leave a Comment


Comment Preview
