jQuery UI dialog box not positioned center screen

后端 未结 23 3147
失恋的感觉
失恋的感觉 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:32

    None of the above solutions seemed to work for me since my code is dynamically generating two containting divs and within that an un-cached image. My solution was as follows:

    Please note the 'load' call on img, and the 'close' parameter in the dialog call.

    var div = jQuery('
    ') .attr({id: 'previewImage'}) .appendTo('body') .hide(); var div2 = jQuery('
    ') .css({ maxWidth: parseInt(jQuery(window).width() *.80) + 'px' , maxHeight: parseInt(jQuery(window).height() *.80) + 'px' , overflow: 'auto' }) .appendTo(div); var img = jQuery('') .attr({'src': url}) .appendTo(div2) .load(function() { div.dialog({ 'modal': true , 'width': 'auto' , close: function() { div.remove(); } }); });

提交回复
热议问题