471,092 Members | 1,227 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Problem with FF2.0 trying to find the y offset of an object.

I’m having a problem with FF2.0 trying to find the y offset of an object.

I've tried several different scripts; all seem to be similar to this one. I keep getting strange values for the Y offset. In stylesheets, I set everything to zero: body { padding:0px; margin:0px }. then placed one single image on a blank page with an href around it. using mouseover to show me the y offset, I keep getting different y offsets depending on the height of the image (manually changed for experimentation). The natural height of the image is 88, yet somehow the offset keeps saying 73.

If I have set everything to zero: 1. shouldn’t the offset always be zero? 2. why does the y offset change every time I change the image height?

Strangely, when the image path had a typo and no image appeared, this displays the correct y offset. place your test image in place of: testImageHere

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<title>obj pos</title>

<script type="text/Javascript">

function findPos(obj) {
var curleft = 0;
var curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop

alert ("x="+curleft+", y="+curtop);


body { padding:0px; margin:0px; }
.container { padding-top:0px; padding-left:0px; }


<div class="container">

<a href="#" onclick="findPos(this);"><img src="images/testImageHere.gif" alt="test" width="96" height="88" border="0" /></a>


Feb 15 '07 #1
1 1120
16,027 Expert Mod 8TB
This page might help.
Feb 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by JasBascom | last post: by
3 posts views Thread by Muhammad Farooq-i-Azam | last post: by
5 posts views Thread by Jay | last post: by
5 posts views Thread by Chuck Gantz | last post: by
1 post views Thread by Mr. Beck | last post: by
3 posts views Thread by Harry | last post: by
2 posts views Thread by =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.