Bootstrap scroll Spy没有突出显示正确的部分

时间:2013-03-05 02:33:59

标签: javascript html

这是我第一次使用bootstrap scroll spy,所以我不确定如果我做错了什么。 (显然我是)这是问题所在。 我不得不使用-190的偏移量,因此红色导航栏的底部位于该部分开始的位置。一旦我应用了偏移量,它就不会突出显示(主动区)主导航上的那个部分。在我向下滚动之前,它会突出显示该部分。

此外,我似乎没有找到一种方法来附加链接以一直向上。因为它必须去主导航。我在哪里放#home ID?


以下是代码:请注意,我没有复制整个HTML,因为它很长,但我还附加了实时链接。

 <header id="global-header">
        <div class="header-cont-info"> Call to schedule your <span class="yellow uppercase">free,</span> no obligation assessment: <span class="yellow">407&#8211;844&#8211;1182 </span></div>
        <!-- Main nav-->
        <nav id="navbar">
          <h1 class="visuallyhidden">Main navigation</h1>
          <ul class="nav"> 
            <li class="home-mn-btn active"><a href="#home">Home</a></li>  
            <li class="services-mn-btn"><a href="#services">Services</a></li>
            <li class="reviews-mn-btn"><a href="#reviews-section">Reviews</a></li>
            <li class="tp-logo"><img src="img/tidy-pools-logo.png" width="332" height="194" alt="Tidy Pools Logo"></li>
            <li class="faq-mn-btn"><a href="#faq">Faq</a></li>
            <li class="contact-mn-btnn"><a href="#contact-section">Contact</a></li>  
            <li class="portal-mn-btn"><a href="#">Customer Portal</a></li>
          </ul>
        </nav><!-- Main nav ends-->
      </header>

 <!-- Services section-->
        <div class="section-dividers-dark"><!--It contains the bottom shadow-->
          <section id="services"><!--Ribbon ends-->
            <p><a href="#" class="buttons yellow-buttons fancybox"><span class="modern-pictogram">W</span> View Pictures of Our Work</a></p>
            <div class="clear-fix"></div>
            <!-- Residential Pool and Spa Maintenance section-->
            <section>
              <header>
                <h2>Residential Pool and Spa Maintenance</h2>
                <p>Enjoy comprehensive weekly service for only $80/month, including:</p>
              </header>
              <ol>
                <li><h3>Cleaning And Debris Removal</h3>
                  <ul>
                    <li> Skim surface and bottom of pool</li>
                    <li>Brush interior surfaces and steps</li>
                    <li>Clean tile</li>
                    <li>Vacuum and clean deck as necessary</li>
                  </ul>
                </li>
                <li><h3>Water Quality Assurance</h3>
                  <ul>
                    <li>Test water and balance</li>
                    <li>Add necessary chemicals</li>
                  </ul>
                </li>
                <li><h3>Equipment Maintenance</h3>
                  <ul>
                    <li>Empty baskets</li>
                    <li>Clean filter</li>
                    <li>Check equipment functioning</li>
                  </ul>
                </li>
              </ol>
            </section><!-- Residential Pool and Spa Maintenance section ends--><br>
            <!-- Commercial Pool Maintenance section-->
            <section>
              <h2>Commercial Pool Maintenance</h2>
              <p>We offer affordable commercial service as well.<br>
                Simply call and we’ll be happy to provide you<br>
              with a customized quote  for your property’s needs.</p>
            </section><!-- Commercial Pool Maintenance section ends-->
            <!-- Water Recovery Services section-->
            <section>
              <h2>Water Recovery Services</h2>
              <p>For green pool/water recovery services,<br>
              simply call for your free quote!</p>
            </section><!-- Water Recovery Services section ends-->
          </section>
        </div>
      <!-- Services section ends-->

      <!-- Reviews section-->
      <!-- Section dividers. These expand 100% and are used to separate the sections-->
      <div class="section-dividers" id="reviews-section">
        <!-- Section inner wrappers. These contain the section max-width-->
        <div class="section-inner-wrapper">
          <section id="reviews">
            <header><!--Ribbon ends-->
              <p><span class="dark-blue">See what our valued customers have to say about Tidy Pools quality swimming pool cleaning and maintenance service.</span><span class="yellow"> This is just a sample of the kind testimonials we have received, and we look forward to adding yours!</span></p>
            </header>
            <ul id="people-reviews">
              <li>&#8220; I have had pools for 27 years. Tidy Pools is the most professional, honest and reliable company I’ve had work for me! Your integrity makes me smile and you’ve always been so fair. Thank you. &#8221; <br>
              <span class="review-names">&#8211; Roxane B.</span></li>

              <li>&#8220; I have had pools for 27 years. Tidy Pools is the most professional, honest and reliable company I’ve had work for me! Your integrity makes me smile and you’ve always been so fair. Thank you. &#8221; <br>
              <span class="review-names">&#8211; Roxane B.</span></li>
              <li>&#8220; I have had pools for 27 years. Tidy Pools is the most professional, honest and reliable company I’ve had work for me! Your integrity makes me smile and you’ve always been so fair. Thank you. &#8221; <br>
              <span class="review-names">&#8211; Roxane B.</span></li>
            </ul>
 </section><!-- Reviews section ends-->

JS

 // ******************************** ANIMATED SCROLLING ********************************
$('#navbar ul li a').bind('click', function(e) {
    e.preventDefault();
    $('html, body').animate({
        scrollTop: $(this.hash).offset().top -190
    }, 300);
    // edit: Opera requires the "html" elm. animated
});

以下是实时网站链接http://tidypools.com/dev/

1 个答案:

答案 0 :(得分:6)

您没有正确设置data-offset,如Twitter Bootstrap documentation中所述。

您需要将<body>标记修改为:

<body data-spy="scroll" data-offset="170" data-target="#navbar">