为了使站点按您希望的方式运行,您需要从每个页面中获取内容并将它们作为部分放在 index.php 页面上。每个部分都有一个唯一的 ID,如下所示:
<div class="section about" id="about">
-- about.php content goes here
</div>
<div class="section contact" id="contact">
-- contact.php page content goes here --
</div>
然后在你的jquery中输入以下代码:
// Jump to target function
$('a[href^="#"]').on('click',function (e) {
var href = $(this).attr('href');
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing', function () {
window.location.hash = target;
});
});
在您的导航中,您将链接放置为
<a href="#about">About Us</a>
当您单击该链接将您带到页面的该部分时,您将看到滚动效果。