Make JQuery UI Dialog automatically grow or shrink to fit its contents

前端 未结 7 1838
遇见更好的自我
遇见更好的自我 2020-12-04 09:28

I have a JQuery UI dialog popup that displays a form. By selecting certain options on the form new options will appear in the form causing it to grow taller. This can lead

相关标签:
7条回答
  • 2020-12-04 09:50

    If you need it to work in IE7, you can't use the undocumented, buggy, and unsupported {'width':'auto'} option. Instead, add the following to your .dialog():

    'open': function(){ $(this).dialog('option', 'width', this.scrollWidth) }
    

    Whether .scrollWidth includes the right-side padding depends on the browser (Firefox differs from Chrome), so you can either add a subjective "good enough" number of pixels to .scrollWidth, or replace it with your own width-calculation function.

    You might want to include width: 0 among your .dialog() options, since this method will never decrease the width, only increase it.

    Tested to work in IE7, IE8, IE9, IE10, IE11, Firefox 30, Chrome 35, and Opera 22.

    0 讨论(0)
提交回复
热议问题