3 ms·
A remark on your fail.js, since you’re engaging here and I figure this could interest you or others: Once there are more than thirty rows, you fade rows in lik
by chrismorgan 3y ago
A remark on your fail.js, since you’re engaging here and I figure this could interest you or others:
Once there are more than thirty rows, you fade rows in like this:
row.style.opacity = 0;
let intervalId = setInterval(function() {
opacity = Number(window.getComputedStyle(row).getPropertyValue("opacity"));
if (opacity < 1) {
opacity = opacity + 0.1;
row.style.opacity = opacity;
} else {
clearInterval(intervalId);
}
}, 100);
This would be better done with a CSS animation or transition—it takes less code, and is smoother.
My suggestion: use animation. Replace the JavaScript with this:
row.classList.add("fade-in");
And add this CSS:
.fade-in {
animation: 1s fade-in;
}
@keyframes fade-in {
from { opacity: 0; }
}
This does behave a little differently, as if the window isn’t visible, it’ll (roughly) wait until you focus the window before playing the animation. Frankly this is even mildly more desirable.
The alternative: use transitions, which are a tad more involved because you have to trigger the value change one frame later, so that it recognises that something has changed and interpolates to it, rather than it just being the initial value and applied instantly. This JS would do:
row.style.transition = "1s opacity";
row.style.opacity = 0;
requestAnimationFrame(() => {
row.style.opacity = 1;
});
Or you could express it with more CSS, like with this CSS + JS:
tr {
transition: 1s opacity;
}
.invisible {
opacity: 0;
}
row.classList.add("invisible");
requestAnimationFrame(() => {
row.classList.remove("invisible");
});
—⁂—
You might also like `vertical-align: middle` on your spin.svg.
—⁂—
On the flag icons, here’s a cool alternative technique: https://en.wikipedia.org/wiki/Regional_indicator_symbol https://en.wikipedia.org/wiki/Regional_indicator_symbol. Lets you avoid needing even images. Unfortunately, I think Windows still doesn’t ship flags, so you’ll get the two-letter country code there. You can get around this by packaging a web font. It’d be nice if someone would neatly package a flags-only font so others can easily use it. Here’s what I did a few months back for https://ganintegrity.com/country-profiles/ https://ganintegrity.com/country-profiles/, resulting in a single 77KB font file:
/**
Copyright 2020 Twitter, Inc and other contributors
Graphics licensed under CC-BY 4.0: https://creativecommons.org/licenses/by/4.0/
Twemoji Mozilla packaging via https://github.com/mozilla/twemoji-colr, subset to only include country flags.
*/
@font-face {
font-family: flag;
/* (Generated with `pyftsubset /opt/firefox-nightly/fonts/TwemojiMozilla.ttf --unicodes="U+1F1E6-1F1FF" --output-file=static/TwemojiMozillaFlags.woff2 --flavor=woff2`.) */
src: url(/static/TwemojiMozillaFlags.woff2) format("woff2");
}
/* Why do we do this? Because at the time of writing Windows doesn’t do flags, so ‹guzzled by HN› will look like “ᴀᴜ” rather than an Australian flag. (macOS and major browsers on Linux do.) */
.flag {
font-family: flag;
}
- mike_d 3y agoThanks! This is incredibly helpful! I searched around a bit at like 3 AM while I was building it, but couldn't find a simple clean example like what you provided. Once traffic dies down i'll swap it out.
- kwar13 3y agowow I just got a lesson in css for free. Thanks for taking the time!
- dlgltlzed 3y agoTalking about animations, the little animation next to "Connected to WebSocket" is an SVG. I did not know until today that SVGs may be animated. Nice to know.
- chrismorgan 3y agoThat’s SMIL. You can also use CSS animations on SVG these days.