开发者

jQuery zIndex div display problem

I am trying to set the z-Index through Jquery, but I need every DIV except for one called importantdiv to b开发者_如何学Ce from 0-100. The only problem is that importantdiv gets a z-index of 40 instead of 510? what Did I do wrong in my jquery code?

<script src="scripts/jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function() {
        var zIndexNumber = 100;
        $('div').each(function() {
            $(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
        });
        $('#importantdiv').css('zIndex', 510);
    });
</script>


try this:

$(function() {
    var zIndexNumber = 100;
    $('div').not($('#importantdiv')).each(function() {
        $(this).css('z-index', zIndexNumber);
        zIndexNumber -= 10;
    });
    $('#importantdiv').css('z-index', 510);
});


For one thing it's:

$(this).css('z-index', zIndexNumber);

not

$(this).css('zIndex', zIndexNumber);


It probably happens because the "each" loop function runs in a separate thread that smash overwrites the importantdiv since the code splits into two threads kinda. You could put an If inside the loop to check for importantdiv and if so skip it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜