reactjs - 根据滚动方向更改反应样式组件的 css
问题描述
我是新手,我想根据滚动方向更改样式组件的一些 CSS。我进行了一些研究并发现了 onScroll 但它似乎并没有根据滚动方向做一些事情。
我的屏幕左侧和右侧各有两个框,向下滚动时,我想将左右底部的框粘贴到屏幕上,而在向上滚动时,我想将左右的顶部框粘贴到屏幕而不是底部框,我不确定是否可能。
我在下面写了一个简单的 html 代码来演示网站的那部分,因为只有左右底部的框是粘性的,类似于我当前的网站。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div style="display: flex; flex-direction: row; justify-content: center;">
<aside style="width: 250px; margin: 20px 20px 0;">
<div style="width: 250px; margin: 0 0 20px; height: 400px; background-color: aqua;"></div>
<div style="width: 250px; margin: 20px 0 0; height: 400px; background-color: darkblue; position: sticky; top: 20px;"></div>
</aside>
<section style="width: 850px; margin: 20px 20px 0; height: 4000px; background-color: darkgray;"></section>
<aside style="width: 250px; margin: 20px 20px 0;">
<div style="width: 250px; margin: 0 0 20px; height: 400px; background-color: aqua;"></div>
<div style="width: 250px; margin: 20px 0 0; height: 400px; background-color: darkblue; position: sticky; top: 20px;"></div>
</aside>
</div>
</body>
</html>
解决方案
推荐阅读
- c# - 在 c# 中图像保存期间共享冲突
- css - 为什么下边框在文本下方移动?
- swift - 更改 Firestore 中的特定值时如何有效更新集合文档?
- laravel - Laravel Spark——同时配置统一费率+按座位定价?
- r - 无法在 R 中安装 openxlsx 库
- html - 使用命令提示符启动“http-server”,它正在运行但无法正常工作
- python - 无法让文本出现在我的 Python 绘图中
- node.js - dynamodb TransactWriteItems 错误:请求了未知操作
- mysql - 在 phpmyadmin 中使用带有 LIMIT 语句的括号时警告“遇到非数字值”
- azure-api-management - 如何批量更新 Azure API 管理命名值?