|
-
Dec 22nd, 2003, 03:11 PM
#1
Thread Starter
Stuck in the 80s
Javascript: Positionin a DIV in Mozilla
Here's the code I'm running to try to align some items in Mozilla:
Code:
function setupDIVs() {
var objMenu = findDom('menubar');
objMenu.style.left = findLeft('logobar') + 10;
objMenu.style.color = '#003399';
}
function findLeft(objectID) {
if (findDom(objectID).offsetLeft) {
return findDom(objectID).offsetLeft;
} else if (findDom(objectID).clip.left) {
return findDom(objectID).clip.left;
} else {
return 0;
}
}
function findDom(objectID){
if (document.all){
return document.all(objectID);
} else if (document.getElementById){
return document.getElementById(objectID);
} else if (document.layers){
return (document.layers[objectID]);
}
}
The color changing works, but the element doesn't move.
Any ideas?
-
Dec 27th, 2003, 06:47 AM
#2
I assume that position is absolute to begin with, right?
A very likely reason for the failure is units. offsetLeft is simply a number, but style.clip.left might be a string containing a number and a unit (px, em, %, ...). If so, "addition" of 10 becomes a string concatenation and the result could be something like "40px10", which of course is an invalid value for the left style.
Another possibility is that the calculation results in a proper number, but then you still have no unit (e.g. "50"). In full or partial standards mode (meaning that you have a DOCTYPE declaration with HTML 4 or any XHTML) Mozilla might well refuse this non-standard property value as the CSS spec requires a unit for non-0 values.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|