Forum Moderators: open
i made a layer/<div> element and i want it to stay where it is (positioned absolutely) when the page is scrolled.
is there any kind of style="??" or something that makes the layer stay stationary when page is scrolled.
is there any way of doing this??
thx
where can i et info on scroll events?
But you have to simulate the window scroll event in NS4+ and Opera.
This menu example [cross-browser.com...] uses my library, but the initialization is close enough to DOM2 that you can see the general setup for a floating element.
var menuAnchor, slidingMenu;
function windowOnload()
{
menuAnchor = document.getElementById('menuAnchor').cbe;
slidingMenu = document.getElementById('slidingMenu').cbe;
window.cbe.addEventListener("scroll", slidingMenuListener);
setTimeout("init()", 250);
}
function init() {
slidingMenu.resizeTo(80,300);
slidingMenu.moveTo(10, menuAnchor.pageY());
slidingMenu.show();
}
function slidingMenuListener()
{
slidingMenu.slideTo(10, menuAnchor.pageY() + document.cbe.scrollTop(), 1000);
}
Just as you thought, usernmame_here, position:fixed is supposed to "fix" a div's position relative to the viewport rather than relative to the page. IE6 doesn't support it, Netscape 6 does, but the scrolling is awkward. Opera 6 renders the page beautifully.
Some day it will be as simple as position:fixed.