1、通过scrollIntoView方法来实现定位:
<a href="javascript:void(0)" onclick="document.getElementById('am').scrollIntoView();">快速定位1</a>
2、通过window.location.hash实现:
<a href="javascript:void(0)" onclick="window.location.hash='am'">快速定位2</a>
里面可以有一个元素的id叫做‘am’就可以快速定位到该元素,比如:
<div id="am" style="background-color: #FFFF99">我在这呢!</div>

本文介绍了两种实现网页元素快速定位的方法:一是使用scrollIntoView方法直接滚动至目标元素;二是利用window.location.hash特性平滑过渡至指定锚点。这两种方法均可有效提升用户体验。
2074

被折叠的 条评论
为什么被折叠?



