【问题标题】:jQuery smooth scrolling on a different webpagejQuery在不同的网页上平滑滚动
【发布时间】:2016-01-23 11:44:56
【问题描述】:

我已经设法使用以下代码在单个页面上平滑滚动。

请注意,HTML 链接存储在 header.php 中并在多个页面中使用,下面是代码 sn-p:

HTML 脚本:

<a class="item" href="index.php#contact">

<a name="contact"></a>

JS 脚本:

$('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,并向下滚动到联系人锚点。

非常感谢您提供任何帮助或建议,我相信这是对某处代码的简单调整。

【问题讨论】:

    标签: javascript jquery scroll jquery-animate smooth-scrolling


    【解决方案1】:

    检查你的href应该是:index.php/#contact

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      相关资源
      最近更新 更多