2011-09-06 31 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