2014-02-09 30 views
0

使用jQuery和引导3我正在尝试创建一个滚动网页页面。这里是Working Demo。到目前为止,它看起来罚款时,在像Section 1Section 2Section 2Section 3序列用户滚动,但我对nav navbar-nav项目一些问题,当用户滚动无序Section 1Section 6等。它看起来像每个项目nav navbar-nav步骤获得目标项目!(你可以在下面的图片查看)滚动到部分的问题

还有另外一个重要的问题Section 7滚动。它不滚动到与其他部分相同的位置,并且有更多的空间。 (你可以在下面的图片查看)

enter image description here

这里是我用于滚动

<script> 
    $(function() { 
     $('a[href*=#]:not([href=#])').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; 
      } 
     } 
     }); 
    }); 
    </script> 

能否请你帮我解决的代码,这些事情jQuery的?谢谢

回答

0

1)最后一节的问题应该很容易解决。最后一部分下方没有足够的“空间”,因此浏览器无法进一步滚动。一个快速和肮脏的修复将是在最后一段的末尾插入一些

<p>&nbsp;</p> 

行。

2)我认为这可能会很棘手。问题是不是部分,而是滚动“html”和“body”元素。这意味着如果用户在第一部分,并点击最后一部分,整个页面就会滚动。用户在滚动动画期间看到所有内容。我认为这是它应该如何工作的。否则,你将不得不改变你实际滚动的方式和内容。

+0

感谢Preli,那么解决方案是什么? – user1760110