Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Getting px position of an element in Integer format

This code works in FF, but not in IE:

parseInt($('.scroller').css('left');

In FF it returns 0px;

In IE it returns NaN.

What's a good way to get a pixel position of an element?

<div class="holder">
    <div class="scroller">
    </div>
</div>
like image 834
kylex Avatar asked Jan 10 '11 23:01

kylex


1 Answers

Use offset:

$('.scroller').offset().left;

offset() returns an object containing the properties left and top, which are the position values relative to the document in pixels.

If you want the position relative to the parent element, use position instead.

like image 158
lonesomeday Avatar answered Nov 01 '22 18:11

lonesomeday