Javascript 当用户单击按钮时,引导向下滚动

Javascript 当用户单击按钮时,引导向下滚动,javascript,twitter-bootstrap,Javascript,Twitter Bootstrap,如何在没有任何连接的情况下使用导航栏来向下滚动页面,特别是在JavaScript部分 我希望发生的事情与示例中的情况类似:一旦用户单击按钮,它将直接转到小节页面,并且应该与示例链接一样平滑滚动 这是我的示例代码 <div class="jumbotron"> <div class="career-jumbotron"> <div class="container"> <a href="#opportunities" class=

如何在没有任何连接的情况下使用导航栏来向下滚动页面,特别是在JavaScript部分

我希望发生的事情与示例中的情况类似:一旦用户单击按钮,它将直接转到小节页面,并且应该与示例链接一样平滑滚动

这是我的示例代码

<div class="jumbotron">

<div class="career-jumbotron">
    <div class="container">
        <a href="#opportunities" class="page-scroll btn btn-xl">
         Button</a>
    </div>
</div> 
<section id="opportunities">
    <div class="container">

    -----sample text-----

    </div>
</section>

-----示例文本-----

这里是一个javascript代码片段,用于平滑滚动相同的页面链接,它监视并将平滑效果应用于从
#
开始的所有链接

您需要添加jQuery库

 $(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 - 135) // adjust this according to your content
           }, 1000);
           return false;
         }
       }
   });
 });

欢迎来到SO。你试过什么了吗?如果你有你的代码,你能和我们分享吗?然后,有人会帮助你。:)下面是代码边缘写入的示例:语法错误,无法识别的表达式:a[href*=#]:not([href=#])