Hacker News new | past | comments | ask | show | jobs | submit login

The advantage of doing it in CSS is that browsers can implement animation themselves.

Animation in JavaScript is a bit of a hack - run a loop with setInterval, change the value of various CSS values for each frame, dynamically adjust the frame rate based on the amount of time left, implement your own easing...

If an animation is described to the browser directly (fade from this value to this value taking this much time) the browser can implement all of the above itself, in a standard way. With access to APIs like Core Animation, the browser can even take advantage of hardware acceleration.

I argue that it makes sense for browsers to provide an animation API. The only remaining question is what form that API should take. It can either be exposed as CSS syntax, or as part of the DOM APIs exposed to JavaScript (document.animateElement(el, ...) for example).

CSS is meant to handle presentation logic, so if you define animation as part of the presentation layer of your site then putting it there isn't really that crazy.




These kind of CSS extensions and hacks really begin to feel like Interweb has gotten a new shiny hammer, and is trying to do everything with it. IMHO a cleaner solution would be to have all interactivity/animation done in JS and CSS for styling only.


Implement the whole animation API in CSS? What if I want the animation to be triggered by button click instead of hover?


Handle the click with javascript, adding a CSS class to the element. The class definitions should look like those of :hover in this example.


:active




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: