tags:

views:

67

answers:

2

How can i walk through all elements and if there is an associated z-index style applied to any elements, set that z-index style to none...?

Then upon completion of the following function, return the original z-index's to there original value.

The small script i am working with.

$(document).ready(function() {

$("<div/>", {
  "class": "DooSuperOverlay"
})
.prependTo("body")
.animate({opacity: 1.0}, 3000)
.fadeOut("slow");

});

Im afraid if there are z-index's applied to the main containing elements in the style sheet, this effect wont work the way it is on the current demo i have. here.

The css may be helpfull:

.DooSuperOverlay {
    position:absolute;
    top:0px;
    left:0px;
    height:100%;
    width:100%;
    background-color:#000;
    z-index:10000;
    }

#%id% {
    position:relative;
    z-index:10001;
}

#%id% .outer_box {
    position:relative;
    z-index:10001;
}

#%id% .inner_box {
    position:relative;
    z-index:10001;
}

If there is any containing div wrapping the #%id% div with a z-index applied it does not work, even if the offending z-index = 1.. ok if z-index:none (defined but as "none")

Here is the html of the css above:

<!--doobox stack begin http://www.doobox.co.uk -->
    <div class="outer_box">
        <div class="inner_box">
        %slice% <!--replaced with content -->
        </div>
    </div>
<!--doobox stack end http://www.doobox.co.uk -->

eg of css that breaks this script:

#container{z-index:1;}

<div id="container">
<!--My html resides here and if any parent has z-index like eg, no matter of value unless none.. this script breaks -->
</div>
A: 

Iterating through the DOM using $('*') would be very expensive. But since the function your running is on document ready then you will know immediately if you have set up any z-index properties > 10000. My best suggestion to you is to simply keep track of the elements you are setting a z-index on. Basically you know know that you probably should never sent a z-index > 10000.

Here is what I would do. Make some limits

Layer 0 (z-index = 0 or none)
  Body
  Navigation
  Other elements

Layer 1 (z-index = 100)
  Some modal dialogs


Layer 2 (z-index = 200)
  a Bar Chart
  a pie Chart

...
Layer n 

Keep going until you cover all the layers you need and manager your z-indicies through your own custom design standards

John Hartsock
Strangely, the z-indexes that may be applied to any element that contains the #%id% dis's above, break this even if the z-index=1..where logic says that the z-index=10001 i have applied should bring this to the fore in all cases... this only works if no parent elements of the #%id% div's have z-index applied, or have the z-index=none... why oh why is the mere fact that a low z-index has been applied to a parent element break this..?
Doobox
Could you please post your whole page including all HTML, CSS and JavaScript? http://jsbin.com
sunn0
A working demo is here http://www.doobox.co.uk/test/test.html .. and a demo with z-index:1 applied to one of the containing divs in the style sheet is here http://www.doobox.co.uk/testsite/ (not working).. i will amend the post to show the offending css that can not always be avoided.
Doobox
Cant really post the whole page as the point of this script is to fit into any page when applied.. the whole css, html and javascript are now posted.. jquery is wrapped in a closure dynamically and call the latest version.
Doobox
actually the script in fact is not breaking under any circumstances.. what in actual fact is happening in the circumstances i have outlined is: the script runs and generates the overlay, but the div that has the highest z-index shown in original post, does not get pulled to the foreground.
Doobox
A: 

I am posting answer instead to be able to format some code.

First: I have interpreted it as the expected behaviour is the overlay fading but on the test page the overlay fading never happens. The #content div has z-index:auto on your example page and changing it to z-index:1 after page has loaded doesn't change anything. I am using Firefox 3.6.3 on Ubuntu.

If I change

<div class="DooSuperOverlay" style="opacity: 1; display: none;"></div>

to

<div class="DooSuperOverlay" style="opacity: 1; display: block;"></div>

once the page has loaded it works just fine so it is probably not a z-index issue.

I suspect it has something to do with:

.animate({opacity: 1.0}, %id=delay%000)

Why is it there? The div already has 1 in opacity and it may interfere with the next line

.fadeOut("slow");

as it does the opposite ie animate({opacity:0})

Also is there no way you can insert

 <div class="DooSuperOverlay"></div>

directly in html code as now the overlay won't be added until after the page has finished loaded.

sunn0