Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery在不同网页上平滑滚动_Javascript_Jquery_Scroll_Jquery Animate_Smooth Scrolling - Fatal编程技术网

Javascript jQuery在不同网页上平滑滚动

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

我已经成功地使用以下代码在单个页面上实现了平滑滚动

注意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.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