2013-12-23 21 views
0

我有一個功能的鏈接,以消除某些div並打開另一個div。我還想scrollTop的的功能添加到頂部,但它不迴應...我認爲的代碼是完美的,但也許我失去了一些東西......scrollTop沒有工作,一旦點擊鏈接與其他jQuery的功能

JQUERY:

// Effect to scroll top NOT WORKING 
    $('.bio').click(function(){ 
     $('html, body').animate({scrollTop : 0},800); 
     return false; 
    }); 

    /* Open and closing feature on the about/faq */ 

    //When button is clicked 
    $('.text-btn').on('click', function(e) { 

     //Prevent url from changing 
     e.preventDefault(); 

     //Find current popup based on data-popup attribute 
     var thisInfo = $('.info-' + $(this).data('info')); 

     //Hide all other popups 
     $('.info').not(thisInfo).fadeOut(0, function(){ 
     thisInfo.fadeIn(400); 
     }); 

     //Show this popup 
    }); 

HTML :

<section class="content-block scroll-pane"> 
        <article class="content-post"> 
         <div class="info info-1" id="info-1"> 
          <p>CEPODS creates commercial &amp; residential environments using shipping containers. Our aim is to create a community of enthusiast with each build of our unique modern designs.</p> 
          <p>CEPODS are seen as efficient and effective pod styled units, when compared to other typical commercial spaces such as brick &amp; mortar, food trucks, tent rentals or temporary (pop-up) stores.</p> 
          <p>CEPODS modern design standards are ideal for anyone interested in operating, marketing, advertising or expanding their presence by using innovative alternative commercial space with shipping containers. The ideal CEPODS clients -are small to large businesses, start-up, pop-up, 2nd store, test retail outlet, and advertising & marketing platforms. Our client base is also expanded to residential and lodging enthusiasts. Many more all welcome.</p> 
          <p>CEPODS expertise is based in architecture, engineering, design/build, real estate, marketing, retail sales and small business management. Our team of professionals shares the same common passion; produce high quality modern design builds.</p> 
          <h1> 
           <a href="#" class="text-btn bio" id="info-2-link" data-info="2">Bio<i class="icon-right-open-gal"></i></a> 
          </h1> 
         </div> 

         <div class="info info-2" id="info-2"> 
          <h1>Micro Spaces LLC</h1> 
          <p>Executive Member: <a href="#"class="pop-btn pop-link" data-popup="1">TIMOTHY DUNLAP/TIAN MAO</a></p> 
          <p>Executive Member: <a href="#"class="pop-btn pop-link" data-popup="2">ANDREW HAGUE II</a></p> 
          <p>Director of Engineering: <a href="#"class="pop-btn pop-link" data-popup="3">RICK DE LA GUARDIA</a></p> 
          <p>Project Architect: <a href="#"class="pop-btn pop-link" data-popup="4">IBRAHIM GREENIDGE</a></p> 
          <h1> 
           <a href="#" class="text-btn bio" id="info-1-link" data-info="1">about<i class="icon-right-open-gal"></i></a> 
          </h1> 
         </div> 
        </article> 
       </section> 

回答

0

當我運行它時,你的代碼似乎工作得很好。

你把你的jQuery放在$(document).ready()裏了嗎?

$(document).ready(function() { 
    // Effect to scroll top NOT WORKING 
    $('.bio').click(function() { 
     $('html, body').animate({ 
      scrollTop: 0 
     }, 800); 
     return false; 
    }); 

    /* Open and closing feature on the about/faq */ 

    //When button is clicked 
    $('.text-btn').on('click', function (e) { 

     //Prevent url from changing 
     e.preventDefault(); 

     //Find current popup based on data-popup attribute 
     var thisInfo = $('.info-' + $(this).data('info')); 

     //Hide all other popups 
     $('.info').not(thisInfo).fadeOut(0, function() { 
      thisInfo.fadeIn(400); 
     }); 

     //Show this popup 
    }); 
}); 

否則,您的會徽可能在頁面上的其他地方。你的控制檯給你任何錯誤?

+0

整個文件位於「$(window).load(function()」下面。其餘的jQ命令都在工作......我試圖將其更改爲document(ready),但它仍然無法工作。在控制檯我得到一個錯誤,但它與此無關......它是一個fontello字體的錯誤。我不明白爲什麼滾動不起作用,下面的jquery工作。我也嘗試插入相同的類名稱作爲其他功能,它仍然不滾動到頂部。ANY想法? –

+0

對不起,不知道,因爲你的代碼正在爲我工​​作。嘗試創建一個空白頁面,只移動上面的部分。那麼,如果是這樣,你可以轉到其他代碼,並在其他地方尋找問題。 –

+0

奇怪的是,當我從chrome變爲firefox時,它工作得很好。 –