How to fix the zIndex issue with jQuery Dialog UI

旧城冷巷雨未停 提交于 2019-12-11 11:23:32

问题


I am having a small issue with the dialog UI. I marked the zIndex value to high number but it seems that it is ignoring it.

The following is my code

        $( "#number-add" ).dialog({
            resizable: false,
            width: 500,
            modal: false,
            autoOpen: false,
            stack: false,
            zIndex: 9999,
            buttons: {
            "Add Contact": function(e) {

            var formData = $('#number-add-form').serialize();

            //submit record
            $.ajax({    
                type: 'POST',
                url: 'ajax/handler-add-new-account-number.php',     
                data: formData,
                dataType: 'json',
                cache: false,
                timeout: 7000,
                success: function(data) {           

                    $('#responceAddNumber').removeClass().addClass((data.error === true) ? 'errorBox' : 'passBox').html(data.msg).fadeIn('fast');   

                    if ($('#responceAddNumber').hasClass('passBox')) {
                        $('#responceAddNumber').fadeIn('fast');
                        $('#add-form').hide();              

                        window.location.reload();
                        setTimeout(function() {

                            $(this).dialog( "close" );                          
                        }, 1000);


                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {

                    $('#response-add').removeClass().addClass('errorBox')
                                .html('<p>There was an<strong> ' + errorThrown +
                                      '</strong> error due to a<strong> ' + textStatus +
                                      '</strong> condition.</p>').fadeIn('fast');           
                },              
                complete: function(XMLHttpRequest, status) {            
                    if (   $('#response-add').hasClass('passBox') ){
                        $('form')[0].reset();
                    }
                }
            }); 



            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }

        }
    });

I set the stack value to false and the zIndex to 9999. What am I doing wrong here for the zIndex not to work? I am using jQuery UI Dialog 1.10.2.

Thanks for your help.


回答1:


I spent far too long grappling with this issue in jQuery UI 1.9. Eventually I settled on this somewhat brute force approach to setting the z-index for my modal dialogs.

$('#dialog').dialog({
    modal: true,
    zIndex: 25,
    stack: false,
    open: function (event, ui) {
        $('#dialog').parent('.ui-dialog').css('zIndex', 26)
            .nextAll('.ui-widget-overlay').css('zIndex', 25);
    }
});

You may need to play with the DOM traversal in the open event to properly select your overlay, or omit it if you are not using a modal dialog, but this has given me good reliable results.




回答2:


Looks like applying the resizeable:false option makes it so the position does not get set which is needed for z-index to work

either set resizeable:true, remove it, or set the parent ui-dialog to have a position:absolute

//after .dialog() call
$( "#number-add" ).parent(".ui-dialog").css({position:"absolute"});

or set a css style have the ui-dialog to have position:absolute

.ui-dialog {
   position:absolute;
}

though not sure how this overall style will affect the functionality of jQuery UI Dialog



来源:https://stackoverflow.com/questions/18988447/how-to-fix-the-zindex-issue-with-jquery-dialog-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!