为什么这个平滑的滚动不会工作?

时间:2016-02-25 17:21:21

标签: javascript jquery html css

我不太了解javascript所以我道歉如果它是一些简单的修复 - 但我想知道如何让这个平滑的滚动到div工作。我有一个固定的侧边栏,跳转到div工作在这里:

<div class="row-offcanvas row-offcanvas-left">
  <div id="sidebar" class="sidebar-offcanvas">
  <div class="col-md-12">
    <center><h1 class="logo">
      <a href="#">
        <img src="assets/images/pglogo.png"/>
      </a>
    </h1></center>
    <ul class="nav nav-pills nav-stacked">
      <li class="active"><a href="#about-me">Home</a></li>
      <li><a class="smoothScroll" href="#discovery">Discovery</a></li>
      <li><a class="smoothScroll" href="#wireframing">Wireframe</a></li>
      <li><a class="smoothScroll" href="#visual-design">Visual Design</a></li>
      <li><a class="smoothScroll" href="#project-development">Project Setup</a></li>
      <li><a class="smoothScroll" href="#test-debugging">Test & Debugging</a></li>
      <li><a class="smoothScroll" href="#final-product">Final Product</a></li>
      <li><a class="smoothScroll" href="#contact">Contact</a></li>

    </ul>
  </div>

我在这里也有javascript平滑滚动功能:

   $(function() {
   $('.smoothScroll').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  var target = $(this.hash);
  target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  if (target.length) {
    $('html,body').animate({
      scrollTop: target.offset().top
    }, 1000); 
    return false;
  }
}
   });
 });

有关为什么这不起作用的任何见解?

0 个答案:

没有答案