javasript有两种方法实现锚点定位:

分类:js小程序

 

有两种方法实现锚点定位:
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>

 

本文链接: javasript有两种方法实现锚点定位:
版权所有:布士收藏夹在网络收集,如有侵犯你的权利, 请联系QQ:641868752。

评论

发表评论

*

* (显示gravatar头像)

Ctrl+Enter快捷回复

© 2014 布士收藏夹 all rights reserved.