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