Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Change z-index?

  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cahnge z-index?

    Ok! this is p\my problem I have a drag and drop script like this:

    <html><head>
    <script language="JavaScript">
    <!-- Hide
    N = (document.all) ? 0 : 1;
    var ob;
    function MD(e) {
    if (N) {
    ob = document.layers[e.target.name];
    X=e.x;
    Y=e.y;
    return false;
    }
    else {
    ob = event.srcElement.parentElement.style;
    X=event.offsetX;
    Y=event.offsetY;
    }
    }
    function MM(e) {
    if (ob) {
    if (N) {
    ob.moveTo((e.pageX-X), (e.pageY-Y));
    }
    else {
    ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
    ob.pixelTop = event.clientY-Y + document.body.scrollTop;
    return false;
    }
    }
    }
    function MU() {
    ob = null;
    }

    if (N) {
    document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
    }
    document.onmousedown = MD;
    document.onmousemove = MM;
    document.onmouseup = MU;
    // End -->
    </script>
    </head>

    <body>
    <div id="a" style="position:absolute;left:50;top:50; z-index:4;">
    <img src="unu.gif" name="s">
    </div>
    <div id="b" style="position:absolute;left:50;top:100; z-index:3;">
    <img src="doi.gif" name="d">
    </div>
    <div id="c" style="position:absolute;left:100;top:50; z-index:2;">
    <img src="trei.gif" name="c">
    </div>
    <div id="d" style="position:absolute;left:100;top:100; z-index:1;">
    <img src="patru.gif" name="h">
    </div>
    </body>
    </html>

    I want to chage z-index . In MD function I must place a command who change z-index of the curent div from let say z-index: 2 to z-index:4.
    How can I do this?
    Thanks!!!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    objectRef.style.zIndex = 1;

    just a hint on accessing css properties in javascript:

    the corresponding property (when accessed by javascript) for every 2-word attribute in CSS which is separated by hyphen (-), is the first word then the second word where the first letter is capitalized.

    examples:
    z-index -> zIndex
    font-size -> fontSize

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks man!!! It was simple In MM function ob.zIndex = 1 and in MU function ob.zIndex=-1 and it works. Now the selectid pcture is always on top of the other.


  •  

    Posting Permissions

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