Forum Moderators: open
scrollTopis your friend, as it tells you how far down the user has scrolled. Here's a bit of code that might get you going:
function putInCenter() {
var d = document;
var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body;
var vpw = self.innerWidth ? self.innerWidth : rootElm.clientWidth; // viewport width
var vph = self.innerHeight ? self.innerHeight : rootElm.clientHeight; // viewport height
var myDiv = d.getElementById('divIDhere');
myDiv.style.position = 'absolute';
myDiv.style.left = ((vpw - 100) / 2) + 'px';
myDiv.style.top = (rootElm.scrollTop + (vph - 100)/2 ) + 'px';
}
The first few lines should deal with compat/quirks modes and browser differences. After that, all that needs to be done is to position the div.
If you need the div to stay where it is while scrolling, use position = fixed (won't work in IE6).