2011-09-06 36 views
2

我期待用JScrollPane中的 「scrollToElement」 API此功能:jQuery的JScrollPane中的scrollToElement

http://dextersgospel.com/index-test.html

說明它的使用可以在這裏找到:

http://jscrollpane.kelvinluck.com/api.html#scrollTo

的問題,我與「stickToTop」的爭論是一致的。當點擊箭頭,我想它帶來的有針對性的DIV視口(不只是隱約可見,因爲它是目前正在做)的頂部。 「stickToTop」參數應該是處理這個問題,但我無法讓它工作。

我試圖實現這個如下,但沒有運氣:

api.scrollToElement(target_div_id, {stickToTop: true}); 

,我已經試過:

api.scrollToElement(target_div_id, true); 

這裏是我當前全碼:

$(function() 
{ 
    /* INITIALIZES jScrollPane on ENTIRE BROWSER WINDOW */ 
    var win = $(window); 
    var isResizing = false; 
    var container = $('#full-page-container'); 
    win.bind(
     'resize', 
     function() 
     { 
      if (!isResizing) { 
       isResizing = true; 
       // Temporarily make the container tiny so it doesn't influence the 
       // calculation of the size of the document 
       container.css(
        { 
         'width': 1, 
         'height': 1 
        } 
       ); 
       // Now make it the size of the window... 
       container.css(
        { 
         'width': win.width(), 
         'height': win.height() 
        } 
       ); 
       isResizing = false; 
       container.jScrollPane(
        { 
         'showArrows':   false, 
         'mouseWheelSpeed':  75, 
         'contentWidth':  960, //So content doesn't jump around 
         'animateScroll':  true, 
         'animateDuration':  600, 
         'hijackInternalLinks': true //HAD TO HAVE THIS FOR ANCHORS TO WORK! 
        } 
       ); 
      } 
     } 
    ).trigger('resize'); 

    //Awesome scrollToY function for our duct tape arrows - no flicker + built w/jScrollPane 
    var api = container.data('jsp'); 
    $('.proposal').bind(
     'click', 
     function() 
     { 
      var target_div_id = '#' + $(this).attr("title"); // gives you the TITLE of the clicked link 
      api.scrollToElement(target_div_id, true); 
      return false; 
     } 
    ); 
}); 

任何關於如何得到JScrollPane中的「stickToTop」參數workfor了「scrollToElement」的方法是非常感激的幫助d!

回答

6

您的代碼一般做工精細,爲什麼它似乎stickToTop選擇是不是這個原因,是建議-X的div的CSS。

stickToTop確實滾動這些div所以它們在頁面的頂部,但是,以確定它們上邊緣它使用邊距填充頂值。因此,它顯示爲* target_div_id * DIV的頂部邊緣滾動後是不是在頁面的頂部(這是不正確的)。它是,它只是jScrollpane考慮到邊距和填充的值。

這個問題的解決方案很簡單,換在另一個DIV的建議-X的div(允許帶班.proposal-包裝說,然後把從CSS邊距和填充頂定義提案divs的定義爲。提議包裝類。

+0

絕對BRILLIANCE!非常感謝WTK。在這裏,它的功能完全 - http://dextersgospel.com/index-test.html – nickff

+0

很高興幫助:)順便說一句,你到達那裏的好網站 - 去德克斯特! ;) – WTK

+1

感謝兄弟! 5美元給你一本書的副本......只是說';) – nickff