3 ms·
Today we have CSS custom properties which do similar things: - Authors can define custom properties as long as they start with a double-dash, like --demo - Au
by err4nt 5y ago
Today we have CSS custom properties which do similar things:
- Authors can define custom properties as long as they start with a double-dash, like --demo
- Authors can leave these values empty, or put any code that doesn't break CSS's syntax inside. This can be CSS values, it can be JSON, it can be other languages, even some JavaScript could be stored in CSS to be read later
- Using JavaScript you can read the values of CSS custom properties, and set them
So it's possible with a tiny bit of JS to re-create what the old IE expression() function used to do in any modern browser in a fully standards-compliant way
- mushyhammer 5y ago> So it's possible with a tiny bit of JS Not really. expression() was evaluated by just moving the mouse around, which is what allowed attaching stuff to your cursor with "just some CSS" https://web.archive.org/web/20120420154658/http://msdn.microsoft.com/en-us/library/ms537634(v=VS.85).aspx https://web.archive.org/web/20120420154658/http://msdn.micro... To do what expression() could do you need several event listeners at least which, I mean, of course you can still do it, but it's really unrelated to CSS Properties and just JavaScript at this point.
- err4nt 5y agoThis is actually part of the design of CSS custom properties. It's not an abuse, but part of how they've been designed to be used. You can trigger updates from your own code programmatically, as well as any event listeners (built-in or custom) or from Observers the browser may have (e.g. Resize Observer, Intersection Observer, Mutation Observer) or any other ways you want to update them!