Last jQuery modal z-index dialog overrides initial modal z-index

I need to immediately show 2 dialog modules. Due to the contents of the first dialog box requiring the use of absolute positioning and z-indexing, the z-index of the overlay is important to me.

The problem is that if I show the first modal index z at 300, the overlay will get the z-index 301. If I then show another modal index with a z-index 500, the new overlay will get the z-index 501. If I close both modalities and I’ll open the first modal again, instead of getting an overlay with a z-index of 301, it will be 503.

Here is a sample code.

<html>                                                                  
<head>                                                                  
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" type="text/javascript"></script>        
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.js" type="text/javascript"></script>        
<script type="text/javascript">              
$(document).ready(function(){
    $('#modal').hide();
    $('#success-message').hide();
    $('#show-modal-button').click(function(){
        $('#modal').dialog({
              modal: true,
              buttons: {
                  OK: function () {
                      $(this).dialog("close");
                  }
              },
              draggable: false,
              title: 'test modal',
              resizable: false,
              zIndex: 400
          });

    });

    $('#modal-button').click(function(){
        $('#success-message').dialog({
              modal: true,
              buttons: {
                  OK: function () {
                      $(this).dialog("close");
                  }
              },
              draggable: false,
              title: 'test modal',
              resizable: false,
              zIndex: 500
          });
    });
});
</script>                                                               
</head>                                                                 
<body>     
<input type="button" id="show-modal-button" value="show modal"/>      
<div id="modal">
    <input type="button" id="modal-button" value="push"/>
</div>                       
<div id="success-message"><p>test</p></div>                
</body>                                                                 
</html>

UPDATE , DOM . , , - . , , .

$('#modal-button').click(function(){        
    $('#success-message').dialog({
        modal: true,
        buttons: {
            OK: function () {
                $(this).dialog("close");
                $(this).dialog('widget').remove();
            }
        },
        draggable: false,
        title: 'test modal',
        resizable: false,
        zIndex: 500
    });     
});
+3
3

, DOM , . , , - . , , .

$('#modal-button').click(function(){        
    $('#success-message').dialog({
        modal: true,
        buttons: {
            OK: function () {
                $(this).dialog("close");
                $(this).dialog('widget').remove();
            }
        },
        draggable: false,
        title: 'test modal',
        resizable: false,
        zIndex: 500
    });     
});
+9

"stack" false:

'stack: false'

+5

'stack: false' .

Setting it to false seems to cause the dialog to recalculate its z-index when it is opened or clicked, or something else.

0
source

All Articles