My ultimate goal is to have a DIV layer positioned perfectly in the center of the page (currently I’m doing do with CSS, but I think the solution may be to go completely with JavaScript, which I tried but didn’t work for me), that upon resizing the window, will never move closer than 20px from the top of the page (<body>).
I’ve been copying and pasting javscript for about a year or so and am just now starting to teaching myself the syntax and objects etc.
I’ve tried 4 or 5 COMPLETELY different ways and my JavaScript just refuses to work at all with any of them. Here is the most recent attempt:
[CODE]#center {
position:absolute;
height:1px;
width:1px;
left:50%;
top:50%;
}
#blockTable {
position:absolute;
left:-420px;
top:-263px;
width:841px;
height:526px;
z-index:1;
outline-color:#000000;
outline-style:solid;
outline-width:thin;
background-color:#CCCCCC;
}
#center is parent to #blockTable
[CODE]var obj = document.getElementById(‘center’);
var objTop = obj.style.top;
var objY = obj.offsetTop;
var winHeight = window.innerHeight();
function center() {
objTop = winHeight / 2 + ‘px’;
}
function keepLogo() {
if (objY < 283)
{
objTop = 283 + ‘px’;
}
else
{
center();
}
}
Thanks to all who help. Let me know if you need more info.
P.S. Is it possible to set offsetTop/Left, or can they only be read? I thought maybe that was the problem so I used style.top to set a new value, but that didn’t work either.