2010-10-20 14 views
2

我正在使用scrollTo插件滾動到某些標題。它只會以較小的增量向上滾動,這是由瀏覽器窗口的高度決定的。它似乎無法識別我正在使用的ID。Jquery scrollTo只能以小增量向上滾動

Click here to view the page,您需要滾動到頁面底部並用兩個手指選擇項目。您需要手動向下滾動並單擊右側的鏈接以查看上述行爲(對不起,這有點複雜)。

回答

0

謝謝你們兩個對你的答案。我已經解決了這個問題,我用CSS隱藏了我父母的名稱標籤div,並用JS顯示。這導致瀏覽器不知道如何找到名稱標籤(或類似的東西)。我刪除了顯示:沒有任何CSS,瞧!

2

無需爲此使用插件。

剛剛嘗試下面的代碼 -

$('html').animate({ 
    scrollTop: $('#id where you want to scroll').offset().top 
    }, 2000); 
+0

使用html和body都可以使歌劇運行兩次代碼。只是HTML應該工作。 – 2010-10-20 13:43:40

+0

@James South - 編輯:) – Alpesh 2010-10-20 13:50:33

2

我用這個小片段的scolling

/// <summary> 
    ///  Scrolls the page to a single matched element. 
    ///  Limitations: The document can only scroll a maximum of it's height. If an element is at the bottom of a page with nothing 
    ///  below it then it cannot move that element to the top of the page as nothing exists to fill the space. 
    /// </summary> 
    /// <param name="target" type="String"> 
    ///  The element to scroll to 
    /// </param> 
    /// <param name="padding" type="Integer"> 
    ///  The padding to add to the scrolling destination. Negative values reduce the scrolling distance. 
    /// </param> 
    /// <param name="speed" type="Integer"> 
    ///  The the speed at which to perform the animation. Positive integers only. 
    /// </param> 
    function scrollTo(target, padding, speed) { 

     // Define our variables. 
     var target_offset, target_top; 

     // Fix our value to add the selector. 
     if (target.indexOf("#") == -1) { 
      target = "#" + target; 
     } 

     // Get the top offset of the target anchor and add any necessarry padding. 
     target_offset = $(target).offset(); 
     target_top = target_offset.top + padding; 

     // Scroll to that anchor by setting the body to scroll to the anchor top. 
     $("html").animate({ scrollTop: target_top }, speed); 
    }