<div
id="test"
style={{ backgroundColor: 'red' }}
onClick={() => {
let test = document.getElementById('a');
document.body.scrollTop = test?.getBoundingClientRect()?.top||0;
}}
>
test
</div>
<a
id="a"
onClick={() => {
let test = document.getElementById('test');
document.body.scrollTop = test?.getBoundingClientRect()?.top || 0;
}}
>
scroll
</a>
js 控制滚动条位置,实现 锚点效果
最新推荐文章于 2024-07-20 13:48:02 发布