0

How do I get following top value?

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

this value is getting creating by some javascript, i think its following:

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) );
    }

now i need this value, I tried this:

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

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

but it does not work - any clue?

user1464175
  • 155
  • 2
  • 11
  • This post may be informative [here](http://stackoverflow.com/questions/6777506/offsettop-vs-jquery-offset-top) – krg Oct 11 '12 at 00:23

1 Answers1

0

Since you are selecting a class try looping through like this:

$('.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 may also help you get what you need. Documentation

Per your comment, I suggest you read documentation on scrollTop(). This seems to be the value you are looking for and it is not the same as the CSS top value.

Jonathan Eckman
  • 2,071
  • 3
  • 23
  • 49
  • i actually need "every" top value - i want to achieve this: http://jsbin.com/exoyab/1/edit but in scrollpath.js the body does not scrollpath the body does not scroll but this handle which actually got a top value...i try it with offset.top right now – user1464175 Oct 11 '12 at 00:50
  • Your example is using `.scrollTop` which gets the current vertical position of the scroll bar for the selected element. Then it checks to see if the value of .scrollTop() is above 409, about mid page, and if it is, fade the element to 100%. See documentation link in my answer. – Jonathan Eckman Oct 11 '12 at 00:55
  • i get this but .scrollTop does only work with the regular scroll bar right? but i dont have the regular scrollbar – user1464175 Oct 11 '12 at 01:03
  • this is basically my code: http://joelb.me/scrollpath/ now i need this fadin in to get working with this scroll bar – user1464175 Oct 11 '12 at 01:09