<p id="firstAnchor"> 锚点 </p>html
<a href="#firstAnchor"> 跳转 </a>vue
js 控制测试
一、location.href = "#firstAnchor"; // firstAnchor为锚点名称 spa
二、window.location.hash = "#firstAnchor"; // firstAnchor为锚点名称插件
经测试:hash只会在跳转到此页面的第一次起做用,再次刷新此页面将不起做用,而href始终起做用htm
参考:scrollIntoView()
能够用来实现锚点效果:
document.getElementById("#firstAnchor").scrollIntoView(true);
详细介绍API https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
vue :vue-scrollto 待续;blog
jQuery: 等待高手补充get