|
|
O'Reilly Book Excerpts: JavaScript & DHTML Cookbook Cooking with JavaScript & DHTML, Part 6
Editor's note: In this sixth and final sample recipe excerpted from JavaScript & DHTML Cookbook, Danny Goodman shows you how to determine the location of a nonpositioned element. And if you've enjoyed sampling the recipes presented thus far, we'll have another tempting morsel for you to sink your teeth into. Danny has written a bonus recipe you won't find in the book. Check back here in two weeks to try it out. Recipe 13.8: Determining the Location of a Nonpositioned ElementNN 6, IE 5 ProblemYou want to ascertain the pixel coordinates of an element that the browser has placed during normal page flow. SolutionThe following
This function is compatible with browsers that support W3C DOM element-referencing syntax. DiscussionThe typical purpose of establishing the absolute location of an element on the page is to position some other element on it or in relation to it. Because the location of inline elements can vary widely with the browser window size and font situation, the values need to be calculated after the page has loaded, is reflowed in response to other dynamic content additions and deletions, or the window is resized. Although some browser versions report the accurate value simply via the This function is not needed for CSS-type absolute-positioned elements because you can obtain the correct coordinates directly via the See AlsoRecipe 11.12 for reading initial style properties set in Danny Goodman has been writing about technology and computers full-time since 1981 and is the author of Dynamic HTML: The Definitive Reference and "The Complete HyperCard Handbook." Return to the Web Development DevCenter. |
|
|
|
|
||||||||