加载中... --°C -- · --% · --
|
加载中... --°C -- · --% · --

Prop For That

AI工具
Prop For That
摘要

Adam推出Prop For That工具,延续Open Props理念,通过数据属性在CSS中创建实时变量,捕捉浏览器通常无法感知的元素,如光标位置、进度值、表单状态、当前时间和滚动速度。用户只需导入库、在HTML中声明,即可在CSS中应用样式。该工具简化了JavaScript与CSS的交互流程,提供更便捷的实时属性控制方案。

No secret that Adam’s all about props. Dude gave us Open Props a good while back for a slew of preconfigured variables for color, shadows, sizing, typography, among much much more. Now he’s back with Prop For That, a similar sorta idea, but mind-blowing in the sense that it creates live props based things CSS can’t normally see in the browser. Things like cursor position, progress values, certain form states, current time, scroll velocity — you know, the stuff that JavaScript sniffs and passes to CSS.

My understanding is that all the script-y stuff is already in the background. All that’s needed is to import the library, declare it in HTML, then style away in CSS.

Like, here’s Chris a long while back with custom properties registered in JavaScript to track cursor position:

CodePen Embed Fallback

Prop For That has that nicely covered. The difference is that we’re working with data attributes that trigger the scripts:

<div class="mover" data-props-for="pointer">...</div>

And plop the relevant props into the styles:

.mover {
  aspect-ratio: 1;
  width: 50px;
  background: red;
  position: absolute;
  left: calc(var(--live-pointer-x, 0) * 1px);
  top: calc(var(--live-pointer-y, 0) * 1px);
}
CodePen Embed Fallback

The demos are where it’s at. Good lord, can Adam put together some classy work.


Prop For That originally handwritten and published with love on CSS-Tricks. You should really get the newsletter as well.

转载信息
原文: Prop For That (2026-06-16T18:36:25)
作者: Geoff Graham 分类: 前端
链接: https://css-tricks.com/prop-for-that/ |声明:转载仅供分享;侵权联系删除。
评论 (0)
登录 后发表评论

暂无评论,来留下第一条评论吧