Closed Thread Icon

Topic awaiting preservation: how to make a div pop up (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=9015" title="Pages that link to Topic awaiting preservation: how to make a div pop up (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: how to make a div pop up <span class="small">(Page 1 of 1)</span>\

 
protoculture
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 02-08-2004 04:40

I'm creating a dhtml popup menu, and am using absolute positioning. I cannot use relative because it pushes my other content around. I need this layer floating on top of my content.

Anyway the problem I'm having is getting the div to always be in the same location. If I use obsolute positioning then the screen width can always change based on the client... ( eg. 40 pixels from left ), well if dude has 2000 pixels wide screen, that'll screw up where my pop-up menu appears. So how can I position this absolutley ?

www.mp3.com/protoculture

Cameron
Bipolar (III) Inmate

From: Brisbane
Insane since: Jan 2003

posted posted 02-09-2004 21:28

You'll need to caculate the distances based on the width of the visible page.

Something like (note: Typed code into the reply window and didn't test it, so there could be typing errors):

code:
posCenter(obj) {
if (document.documentElement && document.documentElement.offsetHeight != null && document.documentElement.offsetWidth != null) {
obj.style.left = (document.documentElement.offsetWidth/2) + (obj.offsetWidth/2) +"px";
obj.style.top = (document.documentElement.offsetHeight/2) + (obj.offsetHeight/2) + "px";
}
}

posCenter(document.getElementById("myElement"));




Although, that'll only work for recent browsers and for IE in standards compliant mode. For older browsers getting the visible page bounds can be tricky, and when IE is in quirks mode all of the document.documentElement properties return null or undefined (can't remember which, so those checks for null above might not pick up IE in quicks mode), instead you'd have to use documen.body.offsetHeight or something like that, not really sure as I always use IE in standards mode by providing a valid XHTML doctype.

Hope that helps.

[This message has been edited by Cameron (edited 02-09-2004).]

« BackwardsOnwards »

Show Forum Drop Down Menu