Gets the absolute x,y coordinate of an element of a page, and you can use the offset () method:
Copy Code code as follows:
<span style= "color: #000066; Font-weight:bold ">var</span> X <span style=" color: #339933 ">=</span> $<span style=" color:# 009900 "> (</span><span style=" color: #3366CC "> ' #DivID ' </span><span style=" color: #009900 " >) </span>.<span style= "color: #660066" >offset</span><span style= "color: #009900" > (</ Span><span style= "color: #009900" >) </span>.<span style= "color: #660066" >top</span>< Span style= "COLOR: #339933" >;</span>
<span style= "color: #000066; Font-weight:bold ">var</span> Y <span style=" color: #339933 ">=</span> $<span style=" color:# 009900 "> (</span><span style=" color: #3366CC "> ' #DivID ' </span><span style=" color: #009900 " >) </span>.<span style= "color: #660066" >offset</span><span style= "color: #009900" > (</ Span><span style= "color: #009900" >) </span>.<span style= "color: #660066" >left</span>< Span style= "COLOR: #339933" >;</span>
Get relative (parent element) Location:
Copy Code code as follows:
<span style= "color: #000066; Font-weight:bold ">var</span> X <span style=" color: #339933 ">=</span> $<span style=" color:# 009900 "> (</span><span style=" color: #3366CC "> ' #DivID ' </span><span style=" color: #009900 " >) </span>.<span style= "color: #660066" >position</span><span style= "color: #009900" > ( </span><span style= "color: #009900" >) </span>.<span style= "color: #660066" >top</span> <span style= "color: #339933" >;</span>
<span style= "color: #000066; Font-weight:bold ">var</span> Y <span style=" color: #339933 ">=</span> $<span style=" color:# 009900 "> (</span><span style=" color: #3366CC "> ' #DivID ' </span><span style=" color: #009900 " >) </span>.<span style= "color: #660066" >position</span><span style= "color: #009900" > ( </span><span style= "color: #009900" >) </span>.<span style= "color: #660066" >left</span ><span style= "color: #339933" >;</span>