惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
爱范儿
爱范儿
罗磊的独立博客
V
V2EX
量子位
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
Jina AI
Jina AI
博客园 - 叶小钗
小众软件
小众软件
博客园 - 【当耐特】
Y
Y Combinator Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell

remy sharp's b:log

Redesign '26 AI for alt text? text-decoration-thickness discrepancies Are We at War with AI Agent “Civilizations”? Before you buy an LTE Pixel Watch (for your teen) I Who Have Never Known Men 16 for Tia The Talented Mr Ripley (Ripley, #1) Dark mode toggles: two states are enough I'm not done using AI On AI Coding and Its Discontents Three Men in a Boat Not All Screen Reader Users Are Blind Progressive Enhancement inside of JavaScript A Firefox-only minimap Pokémon Emerald Human Software Rescued Pokémon Yellow 'VPNs are lawful technical tools,' says EU Court in landmark copyright ruling Image to text The Air Raid Book Club The infinite scroll may become endangered if controversial Calif. law passes In defense of polyfills • Lea Verou This was the first commit via an LLM to git Wildcards In CSS AI Content Is Everywhere on Social Media, Especially LinkedIn Web Platform Wishlist on Vale.Rocks querySelector immediate children with :scope Fundamentally Why we moved our Bluesky data to Eurosky
when-do web component
Remy Sharp · 2026-07-24 · via remy sharp's b:log

I saw recently saw a blog post (which annoyingly I can't find any more, but I'll link it if I do), showing off a web component that if I recall correctly, would show (or hide) it's contents depending on a browser feature (I'd guess using the @supports query).

That reminded me that I wrote a web component that I use quite a bit (particularly with FFConf), which should really be called do-when, but it's not, it's (stupidly) called when-do (the dash, I guess, being a comma in my head).

The component says: when a time occurs or passes, do a what: show, hide or scroll-to.

You can get the code from github - which also includes an interactive demo that lets you try the settings.

What it is

A small web component to toggle on or off depending on wall clock (date) time without affecting the visual layout (with it's own element).

Use case

I've been using this web component on the FFConf event pages for a number of years to reveal the ticket button if a visitor is sitting on the page (though I appreciate that's unlikely!).

<when-do what="hide" datetime="{ticket-live}">
<p>Tickets live at {nice-ticket-live}</p>
</when-do>
<when-do what="show" datetime="{ticket-live}">
<p>Buy <a href="">now</a>
</when-do>

I've also used the what="scroll" for our schedule page, to automatically scroll to the current speaker.

Though I do appreciate my "battle testing" has been rather limited, so if you use this and spot bugs, please let me know!

API

  • what="show|hide|scroll" - the component also throws an exception if a non valid string is used
  • datetime="isodate" - recommended that you include the timezone, ie. "2026-09-13T10:00Z" is 10am on 13th September on UTC
  • apply="classname" optional class name to apply to the when-do element when it activates, useful if you wanted to transition your contents into view, or highlight the newly scrolled element

How it works/styling

The web component makes use of display: contents to prevent itself from modifying the visual layout.

Due to this display method, it means you can't style the element directly, in that styling has no effect.

If you want to style the contents when the element is active, such as when it has been scrolled into view, it's recommended you wrap the child elements it a parent element, such as a div.

You can also use the apply property to indicate the current when-do has activated.


AI wasn't used in any part of this web component (which is also why the demo page is so ugly).

Published under #web & #code. Edit this post