views:

312

answers:

3

This script shows and positions a div
like:

function myfunction()  
{  
   obj.style.visibility = "visible";
   obj.style.width: "100%";  
   obj.style.height = "100%";  
   obj.style.position = "absolute";
   obj.style.top: "0px";
   obj.style.left: "0px";
   obj.style.z-index = "44";  
   obj.focus()  
 }

and so on
<b onclick="myfunction()">Click here</b>

Of course it's a bit more than that, but this is to show you what I'm trying to do. This works well, the div fills the screen like it should.

The problem is when sometimes we display a lot of links so the user has to scroll.. when the div shows its always on the top of the page and the user gets scrolled up there when it gets focus. When the user is done and closes the div, he has to find his way back down the list where he was.

Is there any way to position the div relative to the browsers scroll position?

+2  A: 
balexandre
That totally did it. Can't believe it was that simple :)Thanks
Jonas B
added one way to, instead of waiting for an answer ... put your hand dirty and D-I-Y :)
balexandre
A: 

you have to use an expression in CSS, something like that:

.div {
position:fixed;
top:expression(window.scrollTop + "px");
...
}
Kheu
A: 

could use position:fixed, but you'd lose IE6 unless you use one of the hacks to get around the IE6 incompatibility.

Ty W
IE6 compatibility is not an issue. This webpage will only be shown on a intranet where no clients run IE 6
Jonas B