7 ms·
The thing I'm always surprised about with these sort of CSS hacks: they don't lag my browser. Like, at all. Even the animated ones! Which is really surprising w
by derefr 10y ago
The thing I'm always surprised about with these sort of CSS hacks: they don't lag my browser. Like, at all. Even the animated ones! Which is really surprising when you compare them to literally any other way these illustrations could have been created. A sufficient mess of procedural Javascript to render the same designs would lag horribly. The equivalent Flash would make the browser choppy as all hell. As would a Java applet, if those were even still around. (SVG might not, but for the SVG to animate you'd need to use... CSS.)
Is CSS effectively "free", or is this just not a complex-enough example to start to see problems?
- Aweorih 10y agoI would compare it like this: C is extremely fast php which is built on C is not so fast So css is like C, built on the internal stuff so pretty much no overhead or anything. Javascript animations are like php, built on top of css with just manipulation of the css/dom structure.
- wlievens 10y agoWhat you mean the say is "there are less abstraction layers".
- Piskvorrr 10y ago*fewer
- hueving 10y agoNah, 'less' because abstraction layers are not as defined as we want to believe so they are more like spackle piled onto a foundation. :)
- Piskvorrr 10y agoThat's the best explanation of a language quirk I've heard for a long, long time! :)
- kenbellows 10y agoAs long as we're being pedantic, it's definitely 'fewer'. 'Less' is only used in cases where you couldn't conceptually talk about a single instance of the thing being described. 'Less distance', but 'fewer miles'; 'less abstraction', but 'fewer layers of abstraction'. Even if in practice it may be difficult to find the edges of a single layer of abstraction, the word 'layers' is still metaphorically talking about a collection of individual items, and whenever this is the case we use 'fewer'.
- wlievens 10y agoI know no king but the King in the North, whose name is STARK!
- c-smile 10y ago> Is CSS effectively "free", or is this just not a complex-enough example to start to see problems? Far from being "free" unfortunately. Especially if it is made on CPU side. But modern browsers are trying to use GPU for that. GPU has a primitive operation: render triangle with three colors at corners. So for non-trivial gradients you will need (on CPU side) to do so called triangulation to produce meshes containing such triangles: http://www.svgopen.org/2011/papers/18-Advanced_Gradients_for_SVG/triangle.png http://www.svgopen.org/2011/papers/18-Advanced_Gradients_for.... And then you need to send that mesh to GPU for batch rendering. Quite complex machinery. Flash and Java were trying to do all that on CPU side. But with high DPI monitors (like 300 PPI Retina - 9 times more pixels on screens) CPU rasterization is not the option anymore.
- nostrademons 10y agoFor animations that touch only primitive transformations (scale/translation/rotation/opacity), the browser will usually render the element once on CPU, upload it to the GPU as a texture, and then composite it with the rest of the page on the GPU. That makes things like the spinning BB-8 or the blinking NO VACANCY basically free on the CPU.
- c-smile 10y agoI believe you are wrong. Usually browsers render all primitives as they are but with transformations applied ( https://cairographics.org/manual/cairo-Transformations.html#cairo-rotate https://cairographics.org/manual/cairo-Transformations.html#... ) before rendering. Otherwise you will see weird pixelation effects.
- nostrademons 10y agoInformation comes directly from the Chrome graphics team: https://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome https://www.chromium.org/developers/design-documents/gpu-acc... (I actually spoke with them personally about this while I was still at Google, but there's the design doc. It's been 2 years, so perhaps the internals have changed, but this was also the situation in WebKit at the time as well.) And you do see weird pixelation effects - try rendering some text to a div and then animating 'transform: scale()'. You lose font antialiasing during the animation, which is why many sites that do this will fade out the text first, animate only the bounding box, and then fade the text back in.
- kevinwang 10y agoI definitely had performance issues when I tried taking CSS hacks to the extreme: http://vitamintk.github.io/One-div-pics/ http://vitamintk.github.io/One-div-pics/
- 13of40 10y agoRenders fine on a $99 Windows phone. Crashes the browser on my iPad. The world is a funny place.
- tamana 10y agoThat's a software difference, software doesn't care bow.much your hardware costs.
- 13of40 10y agoI suspect my iPad crashes (all the damned time) because it's running a couple dozen services that take up all the RAM. Not that the Windows phone isn't, but it seems to manage them a bit better.
- ralfd 10y agoFor the record: No crash on an iPad mini 2 (iOS 10 beta) and an ancient old iPhone 4S (iOS 9.3.1). The picture though is not rendered perfectly but has some white lines in it.
- 13of40 10y agoI was using Chrome on an iPad mini 1, and it crashed after I zoomed.
- jjcm 10y agoI like your baby(rage) sized example.
- martin_a 10y agoPlease make the "don´t try to inspect this"-warning bold or bigger. I... well... I tried to inspect it...
- ageofwant 10y agoThe days of yore when hand-crafted artisinal JavaScript could demand a kings ransom is well and truly behind us. Today the linear-gradient() smiths wield their spacetime-hammers in the octarine glow of quietly exploding minds. What a time to be alive.
- oliv__ 10y agothis is poetry
- underwater 10y agoIt's not really comparable to JS animations, because the browser can render once and cache the pixels.
- deleted 10y ago[deleted]
- xg15 10y agoI could imagine it has to do with the fact that CSS is declarative and exposes a lot less "internals" to the user than JS does. This allows browsers to do a whole lot of optimisations (parallel execution, culling, delegation to GPU) without risk of breaking anything. With JS on the other hand, browsers must be careful to keep up the illusion of sequential, single-threaded execution because that's what JS code assumes.
- Retr0spectrum 10y agoHere's an example of where CSS starts to become a bit more expensive: http://www.keithclark.co.uk/labs/css-fps/nojs/ http://www.keithclark.co.uk/labs/css-fps/nojs/ Edit: The site seems to be overloaded. Here's an archive: https://web.archive.org/web/20160702222211/http://keithclark.co.uk/labs/css-fps/nojs/ https://web.archive.org/web/20160702222211/http://keithclark...
- Eupolemos 10y agoThat was cool. For me, it doesn't run well on FF, but neatly in Chrome. Huge difference.
- Asmod4n 10y agoSafari has lower than 1% CPU Usage when running it.
- deleted 10y ago[deleted]
- yAnonymous 10y agoImpressive.
- Rotten194 10y agoIt ran pretty well in Chrome Beta on my phone (~30fps?) for 10 seconds until the browser crashed.
- runeks 10y agoBeautiful! Runs exceptionally smooth using Chrome on an iPad Air 2. I have no doubt the GPU is doing most of the work. Less smooth on the same device using Safari.
- amelius 10y ago> The thing I'm always surprised about with these sort of CSS hacks: they don't lag my browser. Like, at all. That would depend on your browser. Because AFAIK there is nothing in the CSS spec that guarantees any minimum performance. So don't count on it being fast!
- gobusto 10y ago> for the SVG to animate you'd need to use... CSS. Not strictly true; it's also possible to animate SVGs using ECMAScript or SMIL: https://www.w3.org/TR/SVG/animate.html https://www.w3.org/TR/SVG/animate.html
- tlrobinson 10y ago> SVG might not, but for the SVG to animate you'd need to use... CSS The difference is SVG + CSS is a better abstraction for creating illustrations than crazy CSS gradient and box shadow hacks.
- Torgo 10y agotransitions and animation still run pretty bad on mobile browsers.