Ter13
05-12-2006, 05:34 AM
Alright, I'm trying to make a javascript enabled DIV for my webpage. What it SHOULD do, is go behind the body div, and basically compliment a title image that contains part of a background image.
I'm moving the background div with a small java script that simply finds the offset location of the title image, and then matches the background div to that location, making the image seem to be seamless, and go behind the page content.
This is how it should look: http://img81.imageshack.us/img81/9944/problem11pl.jpg
(It looks that way in IE)
And this is how firefox makes it look: http://img143.imageshack.us/img143/8062/problem21jb.jpg
Now, I'll show you the script I used to create it:
The Javascript function to move it:
function locateBackground()
{
var background = getElementsByClass("backgrounddiv");
var offsetTrail = getElementsByClass("titlediv")[0];
var offsetLeft = 0;
var offsetTop = 0;
while (offsetTrail) {
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf("Mac") != -1 &&
typeof document.body.leftMargin != "undefined") {
offsetLeft += document.body.leftMargin;
offsetTop += document.body.topMargin;
}
background[0].style.left = offsetLeft-85;
background[0].style.top = offsetTop;
}
The CSS for the two conflicting DIVs:
DIV.bodydiv
{
width: 640px;
position: relative;
z-index: 2;
overflow: auto;
left: auto;
right: auto;
margin: 0px auto 0px auto;
text-align: left;
}
DIV.backgrounddiv
{
left: 0px;
top: 0px;
position: absolute;
z-index: 1;
}
The HTML is pretty simple here, so I'm leaving it out. 99% of the work is done by the script and the style sheet.
As for the parts I know are broken, well, Firefox doesn't want to relenquish control over the location of the background div, and IE is cooperating just like an obedient program... For once...
Anybody got any tips?
I'm moving the background div with a small java script that simply finds the offset location of the title image, and then matches the background div to that location, making the image seem to be seamless, and go behind the page content.
This is how it should look: http://img81.imageshack.us/img81/9944/problem11pl.jpg
(It looks that way in IE)
And this is how firefox makes it look: http://img143.imageshack.us/img143/8062/problem21jb.jpg
Now, I'll show you the script I used to create it:
The Javascript function to move it:
function locateBackground()
{
var background = getElementsByClass("backgrounddiv");
var offsetTrail = getElementsByClass("titlediv")[0];
var offsetLeft = 0;
var offsetTop = 0;
while (offsetTrail) {
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf("Mac") != -1 &&
typeof document.body.leftMargin != "undefined") {
offsetLeft += document.body.leftMargin;
offsetTop += document.body.topMargin;
}
background[0].style.left = offsetLeft-85;
background[0].style.top = offsetTop;
}
The CSS for the two conflicting DIVs:
DIV.bodydiv
{
width: 640px;
position: relative;
z-index: 2;
overflow: auto;
left: auto;
right: auto;
margin: 0px auto 0px auto;
text-align: left;
}
DIV.backgrounddiv
{
left: 0px;
top: 0px;
position: absolute;
z-index: 1;
}
The HTML is pretty simple here, so I'm leaving it out. 99% of the work is done by the script and the style sheet.
As for the parts I know are broken, well, Firefox doesn't want to relenquish control over the location of the background div, and IE is cooperating just like an obedient program... For once...
Anybody got any tips?