`

锚点快速定位到页面中指定位置

阅读更多

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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics