By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,806 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,806 IT Pros & Developers. It's quick & easy.

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

P: 7
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" "">
<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
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
This page might help.
Feb 16 '07 #2

Post your reply

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