jQuery UI dialog box not positioned center screen

后端 未结 23 3120
失恋的感觉
失恋的感觉 2020-12-01 00:31

I have a jQuery dialog box that is meant to position in the middle of the screen. However, it seems slightly off-center vertically.

Here is the code:

         


        
23条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 01:25

    My Scenario: I had to scroll down on page to open dialog on a button click, due to window scroll the dialog was not opening vertically center to window, it was going out of view-port.

    As Ken has mentioned above , after you have set your modal content execute below statement.

    $("selector").dialog('option', 'position', 'center');
    

    If content is pre-loaded before modal opens just execute this in open event, else manipulate DOM in open event and then execute statement.

    $( ".selector" ).dialog({
    open: function( event, ui ) {
    //Do DOM manipulation if needed before executing below statement
    $(this).dialog('option', 'position', 'center');
    }
    });
    

    It worked well for me and the best thing is that you don't include any other plugin or library for it to work.

提交回复
热议问题