一、錨點
<p id="firstAnchor"> 錨點 </p>
<a href="#firstAnchor"> 跳轉 </a>
js 控制
1、location.href = "#firstAnchor"; // firstAnchor為錨點名稱
2、window.location.hash = "#firstAnchor"; // firstAnchor為錨點名稱
經測試:hash只會在跳轉到此頁面的第一次起作用,再次刷新此頁面將不起作用,而href始終起作用
二、scrollIntoView()
參考:scrollIntoView()
可以用來實現錨點效果:
document.getElementById("#firstAnchor").scrollIntoView(true);
詳細介紹API https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
三、vue組件 和jQuery插件
vue :vue-scrollto 待續;
jQuery: 等待高手補充