【问题标题】:Unable to get Jquery Smooth scrolling to work无法让 Jquery 平滑滚动工作
【发布时间】:2013-06-13 18:45:34
【问题描述】:

我一直在努力让功能平滑滚动到同一页面上的 id。我几乎尝试了在谷歌上找到的所有解决方案。我到了一个地步,似乎一切都应该正常工作,但即使是基本的非 js id 链接也会中断。我目前正在使用从 jquery 网站下载的平滑滚动插件。目前的代码就是这样。我对 JS 或 Jquery 不太了解,所以我认为我只是遗漏了一些东西。我检查了平滑滚动的功能版本的代码,但即使在 我完全中断了页内链接:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Simon Moon Landings</title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Noticia+Text:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.smooth-scroll.js"></script>
<script>
    $(document).ready(function() {
      $('ul.mainnav a').smoothScroll();
    });

  </script>
</head>

<body>
<div class="container">

<div class="menu">
<nav>
<ul class="mainnav">
<li><a href="#one">one</a></li>
<li><a href="#two">two</a></li>
<li><a href="#three">three</a></li>
<li><a href="#four">four</a></li>
<li><a href="#five">five</a></li>
<li><a href="#six">six</a></li>
</ul>
</nav>
<img class="logo" src="images/smlogo.gif" width="450" height="288" alt="Simon Moon Landings Logo" onmouseover="on();" onmouseout="off();"></nav>
</div>

<div class="content">

<div class="section" id="one">
<h4>One</h4>

</div>
<div class="section" id="two">
<h4>Two</h4>

</div>
<div class="section" id="three">
<h4>Three</h4>

</div>
<div class="section" id="four">
<h4>Four</h4>

</div>
<div class="section">
<a id="five"><h4>Five</h4></a>

</div>
<div class="section">
<a id="six"><h4>six</h4></a>

</div>
</div>

</div>


</body>
</html>

【问题讨论】:

    标签: javascript jquery scroll smooth-scrolling


    【解决方案1】:

    我发现了问题。它根本不在脚本中,而是在 CSS 中。我有一个两列布局,菜单和锚点位于一列 (.menu) 中,目标 div 位于另一列 (.content) 我将 poisiton:fixed 应用于菜单并开始工作。

    【讨论】:

      【解决方案2】:

      这里很好用。

      确保 jquery-smooth-scroll 的 URL 正确。

      我使用这个 jquery-smooth-scroll 副本来测试您的代码:https://github.com/kswedberg/jquery-smooth-scroll

      【讨论】:

        【解决方案3】:

        它对我有用。看这个例子:http://jsbin.com/ixefet/1/edit

        我所做的只是将平滑滚动 JavaScript 的 src 更改为在线版本 (https://raw.github.com/kswedberg/jquery-smooth-scroll/master/jquery.smooth-scroll.min.js) 并添加一些文本,以便您可以看到滚动发生。

        听起来您在平滑滚动脚本中使用了错误的 src(如果是这种情况,您的 JavaScript 错误日志应该显示 undefined function: $.smoothScroll 或类似的内容)。

        【讨论】:

          【解决方案4】:

          它在 jsfiddle 上测试时对我有用,

          here you go
          

          http://jsfiddle.net/mastermindw/XvV9W/1/

          【讨论】:

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