html - JavaScript. Absolute position of <li> element relative to browser bounds? -
how know absolute position of <li>
element relative browser bounds?
<html> <body style="overflow: hidden"> <div id="ticker" style="position:absolute; white-space: nowrap;"> <ol style="list-style-type:decimal; "> <li style="float: left; width: 100px; padding: 2px 0px;">test</li> <li style="float: left; width: 100px; padding: 2px 0px;">test</li> <li id="targetelem" style="float: left; width: 100px; padding: 2px 0px;">test</li> <li style="float: left; width: 100px; padding: 2px 0px;">test</li> <li style="float: left; width: 100px; padding: 2px 0px;">test</li> <li style="float: left; width: 100px; padding: 2px 0px;">test</li> <li style="float: left; width: 100px; padding: 2px 0px;">test</li> </ol> </div> <script type="text/javascript" src="ticker.js" language="javascript"></script> </body> </html>
i need way know left value of element <li>
id="targetelem"
.
borrowed http://www.quirksmode.org/js/findpos.html...
// findposition() quirksmode.org // finds **absolute** position of element on page function findposition(obj) { var curleft = curtop = 0; if (obj.offsetparent) { { /* * loop continues until object being investigated * not have offsetparent more. while offsetparent * still there, still adds offsetleft of object curleft, * , offsettop curtop. */ curleft += obj.offsetleft; curtop += obj.offsettop; } while (obj = obj.offsetparent); } return [curleft,curtop]; }
this function should work in ie6, ie7, ie8, safari, firefox , chrome haven't tested thoroughly. also, article might relevant needs...
i hope helps.
Comments
Post a Comment