Forum Moderators: not2easy

Message Too Old, No Replies

What's the Most Robust Way to do an Overlay <div>?

I want to open a "sub-window"

         

cmarshall

9:31 pm on Apr 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a technique I've avoided using in the past, due to difficulties making it work across all browsers. However, its time has come.

First, the environment:

I have a page that presents a long list of entries. It usually requires vertical scrolling to get to some of them. Each entry has a "more info" link.

Clicking on that link calls an AJAX function that fetches the poop on the item in question. I want to display that item on a screen-centered <div> over the list. This is a fairly common technique, and I've seen a couple of good implementations. I like the ones that dim the whole window behind the info.

The main idea is to leave the list in its current position. I just want people to be able to see (and print) the detailed info. When they have a detail page up, I want printing to just print that <div>, and hide the list. No problem. I can do that easily.

Here's the kicker: It needs to work all the way down to IE 5/Win98. If possible, IE 5.0.1. I can probably talk them into letting 5.5/98 be the base. It doesn't have to be slick, just operational. I have an AJAX library that will easily handle these requirements.

What are people's suggestions?

Dabrowski

1:00 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have an AJAX library that will handle this, what exactly would like like suggestions on? Can you elaborate on your reqs a bit?

cmarshall

1:29 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The AJAX part is the easy part. My library handles it very, very well. I almost never worry about the mechanics of that.

The tricky part is the CSS.

I want a robust manner of displaying an overlaid "window" that is actually a <div>, and I wouldn't mind being able to implement some nice effects, as well, such as a gradual transparency, genie effect or darkening the underlying window. However, these can't cause issues with older browsers.

I have actually developed something that works all the way down to IE5.01/98 since posting this, but I hate what I had to do to make it work in IE 5 and 6. I have to use a popup window, as IE will not honor position:fixed.

Basically, this was the first time I have implemented this kind of thing, and I was looking to find out if there are any "best practices" to achieve this effect.

I can usually solve my own problems and develop my own approaches, but it is often best to learn from the experiences of others, rather than find out the hard way, myself.

Fotiman

2:52 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I use the Yahoo UI Library [developer.yahoo.com]'s SimpleDialog [developer.yahoo.com] for this. Cross browser and easy to implement.

cmarshall

3:38 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm checking it out. Thanks!

Dabrowski

3:46 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have solved the position:fixed thing before by wrapping the whole page in a scrolling div, then everything I wanted 'fixed' was outside this.

cmarshall

3:56 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Huh. That's creative.

Can you show a quick example of this?

Dabrowski

4:09 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok, I don't have a link I can send but here's a quick bit of code:


<style>

HTML, BODY { height: 100%; }

DIV.pagewrapper { width: 100%; height: 100% overflow: auto; }
DIV.overlay {
position: absolute; left: 100px; top: 100px;
background: lightblue;
}

</style>

<body>

<div class='pagewrapper'>
Your content goes here, put enough in to make it scroll! Some of that Lorem Ipsum rubbish should do.
</div>

<div class='overlay'>This should stay where it is!</div>

</body>

You'll have to put it together properly but that should do it. Basically it's a full screen div that contains your page, then your overlay is always relative to BODY.

Dabrowski

4:10 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why are we working today? It's a bank holiday you know!

cmarshall

4:56 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must be from Europe. The Germans aren't talking to us today.

By the way, thanks for the snippet. I have something I can try it with.

Dabrowski

5:00 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must be from Europe. The Germans aren't talking to us today.

You must be from the US, as you have no idea where Germany is. ;)

Or did you mean I must be in Europe as you also have a bank hol? I am indeed, UK.

Did you try that example?

cmarshall

5:26 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or did you mean I must be in Europe as you also have a bank hol? I am indeed, UK.

The term "Bank Holiday" pretty much gave you away.

We work with some Germans, so that's where it came from.

What's the occasion?

I gave the example a quick run, and it sort of worked. The problem is that an Absolute position scrolled with the page, so I don't think I did the overflow right.

In any case, I'll mess with it tonight, when I have more time. Lunch break's over.

Dabrowski

11:07 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah that could cause it. If the overflow isn't right then effectively the page DIV isn't really there.

Can't remember but I might have had my overlay before the page content. Shouldn't really matter but if you do it that way you'll have to use z-index to get the overlay back on top.