Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Closed Thread
Firefox 3.6 Css/JS problem?
Old 01-31-2010, 11:12 AM Firefox 3.6 Css/JS problem?
css
Novice Talker

Posts: 6
Trades: 0
It seems the border is not taken into account in the JS offsetTop/Left properties, in FF 3.6. Excerpts

Code:
<div id="wall">
     <div id="small" class="zimg">
       <img src="..." 300x200/>
     </div>
     <br style="clear:both />
</div>
Some CSS
Code:
.zimg {
   border:20px solid #ddd;
    background:#eee;
   overflow:hidden;
    position:relative;
}

#wall {
  margin:50px 0 0 50px;
}


#small {
  width:300px;
  height:200px;
  float:left;
}
And a JS function to calculate the relative (x,y) coordinates of the mouse over the IMG
Code:
function objabs(o) 
{
   var x = 0,y = 0;

    console.log("get_abs: of "+o.id);
   while (o) {
        console.log("  "+o.id+" x("+o.offsetLeft+") y("+o.offsetTop+")  P:"+(o.offsetParent ? o.offsetParent.id : o.offsetParent));
      x += o.offsetLeft;
      y += o.offsetTop;
      o = o.offsetParent;
   }
   return [x,y];
}
Result: mouse (x,y) are always off by the size of the border (20px).
(console.log() is from Firebug to get a proof!:
smpic x(0) y(0) P:small
small x(50) y(50) P:
x(0) y(0) P:null

50px is the '#wall' margin, border is nowhere.
css is offline
View Public Profile
 
 
Register now for full access!
Old 01-31-2010, 11:32 AM Re: Firefox 3.6 Css/JS problem?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Take a look at the box model, the measurements your script returns are for the content area.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
View Public Profile Visit chrishirst's homepage!
 
Old 01-31-2010, 05:50 PM Re: Firefox 3.6 Css/JS problem?
css
Novice Talker

Posts: 6
Trades: 0
Thanks for your answer.

So you are saying the problem is in the script, in the way it calculates the absolute offset of the image (which has no border etc... itself) from the Top and the Left, using offsetTop() and offsetLeft()?

From javascript.com:
offsetTop: gets the vertical offset position of the current element relative to its offset container
offsetLeft: gets the horizontal offset position of the current element relative to its offset container

The function is called as xy = objabs(IMG);

Last edited by css; 01-31-2010 at 05:52 PM..
css is offline
View Public Profile
 
Old 02-02-2010, 11:13 AM Re: Firefox 3.6 Css/JS problem?
css
Novice Talker

Posts: 6
Trades: 0
Anybody?
css is offline
View Public Profile
 
Old 02-03-2010, 11:48 AM Re: Firefox 3.6 Css/JS problem?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.webmaster-talk.com/javasc...ordinates.html
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
View Public Profile Visit chrishirst's homepage!
 
Closed Thread     « Reply to Firefox 3.6 Css/JS problem?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.45719 seconds with 12 queries