Saturday, 3 September 2016

javascript - Absolute .position() value




Sometimes, when I ask for the .position().top value of some object, it does not return the absolute value, i.e. if some picture is added before, the .position().top value does not change. How may I ask for the absolute position of an object (in this case a div)?


Answer



From the jquery docs:




The .position() method allows us to retrieve the current position of
an element relative to the offset parent. Contrast this with
.offset(), which retrieves the current position relative to the

document.




http://api.jquery.com/position/



So use .offset().


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...