页面加载更改为锚点

我正在使用Jquery.Localscroll在锚之间平滑地移动窗口。 如何在页面加载时更改URL以包含锚链接,以便在页面加载时平滑滚动到某个部分。

或者是否有更好的方法在文档加载时滚动到某个部分。

谢谢。

显然,如果您指定要以传统方式滚动到的锚点:

Link 

然后浏览器将自动滚动。

如果您的目的是让浏览器加载页面然后让您的代码启动以平滑(动画)滚动到特定锚点,那么类似这样的东西将起作用:

 // on calling page Link // on "yourURL" page: $(document).ready(function() { // check for "scrollto" parameter and if it exists // use Localscroll to move to specified anchor var match = /[?&]scrollto(?:=([^&]*))?/.exec(window.location.search); if( match != null ){ var anchor = match[1]; // your code to scroll to anchor here } });