jQuery UI dialog box not positioned center screen

后端 未结 23 2941
失恋的感觉
失恋的感觉 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条回答
  • I was having the same problem. It ended up being the jquery.dimensions.js plugin. If I removed it, everything worked fine. I included it because of another plugin that required it, however I found out from the link here that dimensions was included in the jQuery core quite a while ago (http://api.jquery.com/category/dimensions). You should be ok simply getting rid of the dimensions plugin.

    0 讨论(0)
  • 2020-12-01 01:19
    $("#dialog").dialog({
           autoOpen: false,
            height: "auto",
            width: "auto",
            modal: true,
             my: "center",
             at: "center",
             of: window
    })
    

    This solution does work but only because of the newer jQuery versions ignoring this completely and falling back to the default, which is exactly this. So you can just remove position: 'center' from your options if you just want the pop up to be centered.

    0 讨论(0)
  • 2020-12-01 01:22

    Just solved the same problem, the issue was that i did not imported some js files, like widget.js :)

    0 讨论(0)
  • 2020-12-01 01:23

    I had to add this to the top of my HTML file: <!doctype html>. I did not need to set the position property. This is with jQuery 3.2.1. In 1.7.1, that was not needed.

    0 讨论(0)
  • 2020-12-01 01:23

    This is how I solved the issue, I added this open function of the dialog:

      open: function () {
                    $('.ui-dialog').css("top","0px");                                
                        }
    

    This now opens the dialog at the top of the screen, no matter where the page is scrolled to and in all browsers.

    0 讨论(0)
  • 2020-12-01 01:24

    Simply add below CSS line in same page.

    .ui-dialog 
    {
    position:fixed;
    }
    
    0 讨论(0)
提交回复
热议问题