7 ms·
Glitch effect on text in pure CSS
- sgtnoodle 5y agoThe effect doesn't appear to work very well at all in chrome on my Android phone.
- deleted 5y ago[deleted]
- k_ 5y agoYeah, got same issue on desktop. I can see how it's supposed to work but it doesn't work on dark themed systems because colors don't match at all.
- high_byte 5y agoBrave on Android - works beautifully!
- zoidb 5y agoSame on firefox
- labster 5y agoSame on MobileSafari
- Angostura 5y agoWorks well on desktop Safari
- prirai 5y agoWorks on Styx for Android.
- mikeiz404 5y agoTip: Turn off dark mode If the background is dark blue you won’t be able to see the effect very well.
- _def 5y agoI want a dark mode switch in my browser so badly
- ruune 5y agoDark Reader is kinda that no? Forces almost anything into dark mode without breaking too much, but you can turn it off per site any time
- Moru 5y agoDidn't even have to disable darkmode with Dark Reader [0], the lower glitching works just fine. [0] https://darkreader.org/ https://darkreader.org/
- prirai 5y agoHow about a per website switch?
- jspash 5y agoI think I'm one of the few who doesn't prefer dark mode. The reason is Apple no longer offer a non-super-glare screen on their laptops any more. I bought an MBP about 10 years ago, and the choice between a "matte" screen or "make everything more difficult to see in every environmental condition except inside the Apple Store" screen. Obviously I went for matte. In their infinite marketing wisdom, Apple has removed the matte option.
- bondolo 5y agoI started on monochrome dark screens with white, green or orange phosphors. When I first started (briefly) using a Lisa in 1983 and then a Macintosh in 1984 I found that I really liked the paper-white look. Eventually I decided that I preferred that the theme match the ambient lighting conditions. The recent operating system and browser features to provide adaptive behaviour is exactly what I sought. I now use light themes during the day–I am also a fan of natural light, and dark themes at night with reduced blue and lower colour saturation. I personally don't understand the preference for dark themes in bright ambient lighting. For me it seems to induce more eyestrain than relieving it.
- chrismorgan 5y agoA nice thing about the SVG version is that the entire effect is just a filter, and so you can apply it to any element: h2 { filter: url(https://dustri.org/b/files/glitch.svg#filter); } Now as it stands, this won’t work perfectly in all cases because the animation uses pixel values instead of percentages, so that it’s tied to an approximate text size. By comparison, the CSS version can only be applied to text, and requires duplicating the text content at least once (the article duplicates it once in an attribute value, which is sufficient only for plain text; if you wanted any mixed formatting like bold or italics, you’d need to duplicate the element twice). Also of glitch.svg: 6ßpx looks like an interesting number. Wonder if the error is intentional or not.
- zeeZ 5y agoẞ is right next to 0 on a German keyboard. Interestingly, searching for "6ßpx" gives a few results. This is probably the culprit, going by author name: https://codepen.io/DirkWeber/pen/ArFvk https://codepen.io/DirkWeber/pen/ArFvk
- _the_inflator 5y agoNice catch. :)
- mro_name 5y ago…and the CPU skyrockets. Uh.
- dspillett 5y agoIt shouldn't cause reflow by my understanding, the content never changes size, so the CPU hit should be minimal normally. It is going to consume unnecessary bandwidth and look messy if looking at it in a browser running remotes (via RDC, VNC, etc) but other methods like animated gifs will have that same effect too. In any case, for an animation like this I'd set it to run through a few times, perhaps just once, then stop instead of bouncing around infinitely. Or have a long frame at then end of the sequence so that it only animates occasionally.
- lelandfe 5y agoAlternatively, could use an IntersectionObserver to stop and start it.
- dspillett 5y agoThat too if off-screen animation is causing excess CPU use. Though the loop than ends or only results in occasional animation has another rather nice benefit: less stuff jiggling around to drag my attention away from what I'm actually trying to look at. And using that will break the articles “with pure CSS” intent.
- mro_name 5y agoI see ~84% on one core in Firefox.
- dspillett 5y agoIf something that shouldn't cause reflow and isn't animating a lot of content (or animating insanely fast) is eating bags of time on a modern CPU, I would suggest that is a browser bug not a problem with the idea. Though do make sure you are understanding that 84% figure. Is it really that much of a full speed core or that much of one that is in a low power mode because none of the CPU needs to be at full speed ATM. CPU loading read from task manager apps and similar can be quite misleading these days.
- simion314 5y agoI am mostly avoiding GUI stuff in my work, but from my experience when you combine css animation with "infinite" then you get a constant CPU load, is it worth it? Are there more efficient way?
- zero_shift 5y agoAnimations like this shouldn’t require much CPU load. The actual 2D translation can be done on hardware providing no reflow occurs.
- simion314 5y agoWhat is the correct way to check? I see 8% on a chrome thread and 2% on other chroem thread with only this page opened. A static page should use 0% . This percentages are per core.
- capitainenemo 5y agoThe page regrettably is rendering animations in an SVG. In my experiments in the past, all browsers tended to optimise SVG animation, of all kinds, poorly. (CSS, animateMotion, JS - well, JS always performs badly obviously but..). I think it'd be worth trying to translate this to CSS on text in a web page and see if the performance issues are still there. One can do it transparently these days with CSS filters. Or just draw against same colour as page background. In fact, I think I'm going to give this a try. Will update here, but might take a while to get to it. I also wonder if it could be done more simply. this is basically just slices of offset text right? Also, those clip rects are pretty large. Wonder if that would impact browser texture allocation.
- simion314 5y agoSo my question is in general, animate infinite , is it a bad idea for a simple web page ? My experience was me having to put an emergency fix live because someone made such a css change that had for some reason very noticeable impact on OSX but not on Windows and Linux (though I could see the CPU usage in Linux there was no visible lag). I also remember a big issue with a blinking cursor, so I am thinking why is such heavy animation APIs not coming with giant warnings.
- Aeolun 5y agoWell, the iOS Firefox version is certainly a glitch. But probably not the one the author intended.
- Kibranoz 5y agoIt’s because it uses WebKit instead of Chromium or KDE
- lostgame 5y agoIt’s broken on Dark Mode. Needs an extra bit of CSS to determine whether it’s in dark mode or not. The top example is just a GIF, so that's whatever - but the bottom example, which is actual text using this CSS trick, flickers white in a way that unfortunately ruins the illusion of the experience with a black background. The code needs to use CSS's 'prefers-color-scheme' to differ between background colours for the effect. This could also be used, for that matter; to auto-invert the 'text' colour. :)
- azemetre 5y agoThe blog briefly touches on it, but what does the data attribute 'data-text' enable? I'm kinda confused, I do some data visualization work professionally and I understand how overlay patterns on SVGs work with the 'fill' property and IDs but lost with what the 'content' property is actually doing. Why is it necessary to replace the h1 text with identical text? What does 'content' enable? It seems unnecessary to replace the text with the same text right?
- ericwood 5y agoThe `data-text` attribute is used to set the `content` of the `before` and `after` pseudo-elements[0], effectively creating two "clones" of the original text. These get their own text shadows and clipping animations applied, which creates the effect. You can grab attributes from elements using `attr`[1], which they're using alongside `content`. [0] https://developer.mozilla.org/en-US/docs/Web/CSS/::after https://developer.mozilla.org/en-US/docs/Web/CSS/::after [1] https://developer.mozilla.org/en-US/docs/Web/CSS/attr https://developer.mozilla.org/en-US/docs/Web/CSS/attr()
- azemetre 5y agoThanks for the explanation, I've never seen the attr() property before. A lot of similar codepens I've seen in the past, that do fancy stylings, are suddenly making sense. I always struggle to change my mental model about css to be more expressive, but now many wheels are starting to turn.
- ericwood 5y agoGlad I could help! This is definitely weirder CSS territory but it unlocks some really wonderful techniques.
- proexploit 5y agoIt's not replaced, it's in addition to the text. The HTML gives you one copy in black, then ::before & ::after are used to create copies in red and lime green. Partially showing those copies is what give you the glitch effect. `::before & ::after` are pseudo-elements and a very common way of creating independently styleable elements when doing CSS effects like this `content` is a property you can use to add text to those elements (he could have also just written `content: 'Artificial Truth';` if he preferred - having it as a data-attribute puts it right next to the "real" text and makes things easier to maintain) `attr(data-text)` sets the value of content to the value of an attribute of the HTML. data-* is a common convention for creating value that aren't used for display. It is not possible, to my knowledge, to access the text contained within the `<h1>` with CSS only, hence the above choices.
- rrix2 5y agoIf you're going to use this, please also use `prefers-reduced-motion` media queries to disable it, it's made my some of my friends ill when i had it on my site. https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion https://developer.mozilla.org/en-US/docs/Web/CSS/@media/pref...