Javascript jQuery在不同网页上平滑滚动
我已经成功地使用以下代码在单个页面上实现了平滑滚动 注意HTML链接存储在header.php中,并跨多个页面使用。下面是一段代码片段: HTML脚本:Javascript jQuery在不同网页上平滑滚动,javascript,jquery,scroll,jquery-animate,smooth-scrolling,Javascript,Jquery,Scroll,Jquery Animate,Smooth Scrolling,我已经成功地使用以下代码在单个页面上实现了平滑滚动 注意HTML链接存储在header.php中,并跨多个页面使用。下面是一段代码片段: HTML脚本: <a class="item" href="index.php#contact"> <a name="contact"></a> $('a[href="index.php#contact"]').click(function (e) { // user clicks on html link e
<a class="item" href="index.php#contact">
<a name="contact"></a>
$('a[href="index.php#contact"]').click(function (e) { // user clicks on html link
e.preventDefault(); // prevent the default behaviour that occurs in the browser
var targetOffset = $('a[name="contact"]').offset().top; // define a variable to point at a particular section & offset from the top of browser
$('body').animate( // create animation
{ scrollTop: targetOffset }, 1000); // scrollTop property = target variable
});
问题:
当我转到另一个网页并单击联系人链接时,它不会链接回index.php#contact
,并向下滚动到联系人定位点
非常感谢您的任何帮助或建议,我相信这只是代码中的一个简单调整。检查您的href,它应该是:index.php/#contact