javascript - 单击链接时让两个 div 滚动到不同的部分 - React
问题描述
我试图将我的页面分成两侧,当我单击一个链接时,我希望左侧向下滚动 n 数量,右侧和侧面滚动到不同的 n 数量。
我正在尝试使用 scrollToView 但这证明很困难。
const test = useRef(null)
const temp = useRef(null)
useEffect(() => {
test.current.scrollIntoView({ behavior: "smooth" })
temp.current.scrollIntoView({ behavior: "smooth" })
})
return (
<div>
<div
id="left"
style={{
width: "50%",
float: "left",
}}
>
<div
style={{
height: "95vh",
overflow: "hidden",
}}
>
<div id="okay" style={{ height: "95vh" }}>
1
</div>
<div style={{ height: "95vh" }}>2</div>
<div ref={test} style={{ height: "95vh" }}>
3
</div>
</div>
</div>
<div id="right" style={{ width: "50%", float: "right" }}>
<div
style={{
height: "95vh",
overflow: "hidden",
}}
>
<div id="okay" style={{ height: "95vh" }}>
1
</div>
<div ref={temp} style={{ height: "95vh" }}>
2
</div>
<div style={{ height: "95vh" }}>3</div>
</div>
</div>
</div>
)
例如,我希望左边滑到第三个 div,右边滑到第二个
解决方案
推荐阅读
- php - PHP 运行 curl 命令
- java - Java 测试:当实例符合 GC 条件时如何运行自定义代码?
- python - 等值线图未显示
- python - 安装 Python 包的最旧版本的依赖项
- python - 如何使用 groupby 子句中包含的列创建数据框?
- mysql - 使用 mysqlQuery 重复某些值时未获得预期结果
- dictionary - 删除python中打印语句中的空格
- python - 将数值分组到类别中
- openssl - 在 CentOS linux 中创建 CA 时权限被拒绝
- android - Androidx fontscale 在华为 Mate20 上不起作用