How to auto-center jQuery UI dialog when resizing browser?

前端 未结 6 1249
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 07:44

When you use jquery UI dialog, all works well, except for one thing. When the browser is resized, the dialog just stays in it\'s initial position which can be really annoyin

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 08:33

    Alternatively to Ellesedil's answer,

    That solution did not work for me straight away, So I did the following which is also dynamical but shortened version:

    $( window ).resize(function() {
        $(".ui-dialog-content:visible").each(function () {
            $( this ).dialog("option","position",$(this).dialog("option","position"));
        });
    });
    

    +1 for Ellesedil though

    EDIT:

    Much shorter version which works great for single dialogs:

    $(window).resize(function(){
        $(".ui-dialog-content").dialog("option","position","center");
    });
    

    It is not necessary for .each() to be used perhaps if you have some unique dialogs which you dont want to touch.

提交回复
热议问题