我正在使用 History.pushState 将我的站点 URL 更改为 /name,它正在工作,但页面不会滚动到它应该滚动到的站点位置。
索引.php:
<nav>
<ul>
<li><a href="#work">Work</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li>Blog <!-- Coming Soon... --> </li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
<article class="content" id="work">
...
<article class="content" id="about">
...
jquery.page.js:
_saveState = function( chapter ) {
if (History.getState().url.queryStringToJSON().chapter !== chapter) {
var page;
if (chapter == 1)
page = "/work";
if (chapter == 2)
page = "/about";
if (chapter == 3)
page = "/services";
if (chapter == 4)
page = "/blog";
if (chapter == 5)
page = "/contact";
else
page = '?chapter=' + chapter;
History.pushState(null, null, page)
}
},
...
_goto = function( chapter ) {
var chapter = chapter || History.getState().url.queryStringToJSON().chapter,
isHome = ( chapter === undefined ),
$article = $( chapter ? '#' + 'chapter' + chapter : '#' + 'introduction' );
...
当用户单击导航菜单中的链接时,我如何使页面跳转到它假定的位置,如我一直在关注的教程中所见?