Results 1 to 7 of 7

Thread: Javascript\CSS inline floating div problem

  1. #1
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default Javascript\CSS inline floating div problem

    Hi guys,
    I was recently helping someone out on the forums, when I modified one of my ideas to work for my website. The only problem is that I need the 1x1 semi-transparent png to be ontop of the page's content, but below the actual popup div. Also, is there any way for the div to be auto centered in the document?
    Code:
    <html>
    <head>
    <style>
    div#container {
    background: #CCCCCC;
    border: 1px solid black;
    position:absolute;
    left:-9999px;
    top:-9999px;
    width: 200px;
    z-index: 2;
    }
    #body
    {
    z-index: 0;
    }
    #top
    {
    z-index: 1;
    }
    </style>
    <script>
    function init(x)
    {
    if(x=="show"){
    document.getElementById("container").style.left="200px"
    document.getElementById("container").style.top="200px"
    document.getElementById("top").style.background="url('t.png') repeat"
    }
    if(x=="hide"){
    document.getElementById("container").style.left="-9999px"
    document.getElementById("container").style.top="-9999px"
    document.getElementById("top").style.background="none"
    }
    }
    </script>
    <body id="top">
    <div id="body">
    <div id="container">
    <p>various text goes here</p>
    <input type="button" onClick="init('hide');" value="Hide Text">
    </div>
    <input type="button" onClick="init('show');" value="Show Text">
    Some random Text
    </div>
    </body>
    </html>
    THANKS.
    The Image could'nt be uploaded...
    Last edited by fileserverdirect; 03-11-2008 at 01:18 AM.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Does Anybody know how to do this?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. #3
    Join Date
    Feb 2007
    Location
    England
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default try

    See here
    http://www.wpdfd.com/editorial/thebox/deadcentre4.html

    Do you really need to add a transparent .png? Surely you can do what you want with CSS.

    I thought divs with no background were transparent.

    Have you tried modifying your code to only alter the class of the div instead of its style attributes?

  4. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Thanks for the link.
    The effect that I am trying to get is a "lightbox-like" effect where the "popup" is on the topmost section, and then underneath it a semi-transpaernt overlay, so opacity 50%, and then the rest of the body underneath it all.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  5. #5
    Join Date
    Feb 2008
    Posts
    42
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Default

    I center elements in the page by adding a "wrapper" div around my viewable content, then you can simply use the offsetTop and offsetLeft values to position according to the wrappers offsetWidth and offsetHeight. as far as having one thing on top of another, check out quirksmode.org's javascript CSS compatability reference under "zIndex", the higher the number, the close it is to the front.

  6. #6
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    I am using z-index already, but I do not know how to give it a "lightbox-like" effect.
    Do you know how to do this?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  7. #7
    Join Date
    Feb 2008
    Posts
    42
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Default

    the only "lightbox's" I've used where light tables...is the div supposed to illuminate the png or visa versa? first I wouldn't try to turn the body background on and off, I would set a second div with the png as the background, also instead of starting container at -9999 -9999 why dont you just try...
    Code:
    if(x=="show"){
    document.getElementById("container").style.display="block"
    document.getElementById("wrapper").style.backgroundImage="t.png"
    }
    if(x=="hide"){
    document.getElementById("container").style.display="hidden"
    document.getElementById("wrapper").style.backgroundImage="none"
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •