javascript - React - 将变量传递给 css 表
问题描述
我想了解如何将值从 React 组件传递到 css 样式表。
基本上我有一个
.container {
height:100vh;
width:100vh;
background-image:url(...)
}
.container h1{
display:flex;
justify-content:center
transform:translateY(calc(-47%+0px)
letter-spacing:0px
}
当用户向下(或向上)滚动时,我会将 0px 更改为在我的 React 组件(currentScrollY)上获得的值,旁边是增加(或减少 - boolean goingUp)字母间距和 Y 轴上的平移。
const prevScrollY = useRef(0);
const [goingUp, setGoingUp] = useState(false);
const onScroll = (e) => {
const currentScrollY = e.target.scrollTop;
if (prevScrollY.current < currentScrollY && goingUp) {
setGoingUp(false);
}
if (prevScrollY.current > currentScrollY && !goingUp) {
setGoingUp(true);
}
prevScrollY.current = currentScrollY;
console.log(goingUp, currentScrollY);
};
谢谢
解决方案
推荐阅读
- ag-grid - AG 网格除显示行总计外,还显示百分比行总计
- google-cloud-platform - 创建 Bigtable 副本集群会产生度量错误
- c# - 在 IIS 上运行的 ASP.net 上的超长 TTFB
- php - 如何在 Twig 的标题下显示名称列表
- pandas - 处理`read_csv`的本地时间变化缓慢的熊猫
- ruby-on-rails - NoMethodError: nil:NilClass 的未定义方法 `<'
- opengl - GL_DEPTH_CLAMP 无效(反向 z)
- python - Django 测试用例测试模型失败
- php - 通过 php7.1 后的参数太少。3 个参数通过,4 个参数预期。动态创建图像的脚本
- postgresql - 错误:运营商不存在:没有时区的时间> = bytea