2012-10-11 104 views
0

如何獲得最高價值?scrollpath.js獲得最高價值

<div class="sp-scroll-handle" style="top: 1.0416666666666665px; "> </div> 

這個值越來越被一些JavaScript創建,我認爲它的下面:

function dragScrollHandler(e) { 
     var dragStep, 
      y = e.clientY - scrollBar.offset().top; 

     dragStep = limitWithin(Math.round(y/scrollBar.height() * (pathList.length - 1)), 0, pathList.length - 1); 

     scrollToStep(snap(dragStep, STEP_SIZE)); 
    } 

現在我需要這個值,我想這一點:

$('.sp-scroll-handle').scroll(function() { 

    var top_value = $('.sp-scroll-handle').css("top"); 
    $('.settings b').text(top_value);} 
}); 

,但它不工作 - 任何線索?

+0

這篇文章可能是內容豐富的[這裏](http://stackoverflow.com/questions/6777506/offsettop-vs-jquery-offset-top) – krg

回答

0

既然你選擇一個類嘗試這樣的循環通過:

$('.sp-scroll-handle').each(function(i) { 
    if(i=0){ 
    //assuming you want the first .sp-scroll-handle top value 
    $('.settings b').text($(this).css('top')); 
    } 
}); 

offset.top也可以幫助你得到你所需要的。 Documentation

根據您的意見,我建議您閱讀關於scrollTop()的文檔。這似乎是您正在查找的值,它與CSS top的值不同。

+0

我實際上需要「每個」最高價值 - 我想實現這一目標: http://jsbin.com/exoyab/1/edit但在scrollpath.js身體不滾動身體不滾動,但這個手柄實際上有一個頂級的價值......我現在試着用offset.top – user1464175

+0

你的例子是使用'.scrollTop'獲取所選元素的滾動條的當前垂直位置。然後檢查.scrollTop()的值是否大於409,大約是中頁面,如果是,則將該元素淡化爲100%。請參閱我的答案中的文檔鏈接。 –

+0

我得到這個,但.scrollTop只適用於正常的滾動條嗎?但我沒有普通的滾動條 – user1464175