Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  178] [ 4]  / answers: 1 / hits: 38984  / 13 Years ago, wed, march 16, 2011, 12:00:00

I have basically 2 div elements. The first is a scrolling container and the second one is an element that is placed in the container. I would like to find the y-position relative to the scrolling container. I wrapped all of it into a piece of example-code titled How to find Mr. Blue?



<div style=height:100px; border:solid 1px black; overflow-y:scroll;>
Please scroll down...
<br/>
<div style=height:400px;>
</div>
<br/>
<div id=MrBlue style=height:20px; background-color:blue; color:white>
Mr. Blue
</div>
</div>


So I would like a JavaScript / jQuery statement that alerts the vertical-position of the Mr. Blue. div relative to the scrolling container.



Ps. If you would like to 'fiddle' with mr. Blue, check http://jsfiddle.net/KeesCBakker/Qjr5q/.


More From » jquery

 Answers
5

If you can add css position: relative to the wrapping/scrolling container then it's as simple as



document.getElementById('MrBlue').offsetTop


and jsfiddle example http://jsfiddle.net/eU3pN/2/


[#93252] Tuesday, March 15, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yusuf

Total Points: 167
Total Questions: 97
Total Answers: 108

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;