滚动路径.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);}
});

但它不起作用 - 任何线索?

由于您正在选择一个类,请尝试像这样循环:

$('.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还可以帮助您获得所需的东西。文档

根据您的评论,我建议您阅读 scrollTop() 上的文档。这似乎是您正在寻找的值,它与 CSS top值不同。

最新更新