简体   繁体   English

缓存的JavaScript对话框位置问题

[英]JavaScript Dialog Box Position Issue with Cache

I'm having trouble when it comes to the positioning of my JavaScript dialog box, my dialog box loads automatically when the user enters the page and it should centre in the middle of the page. 我在确定JavaScript对话框的位置时遇到了麻烦,当用户进入页面时,对话框会自动加载,并且该对话框应该居中。 The problem is it will centre when i cache refresh the page however with a normal refresh it doesn't. 问题是当我缓存刷新页面时它将居中,但是使用常规刷新则不会。 On a normal load the top style property is set to 432px On a Cache refresh the top style property is set to 299px 在正常负载下,top style属性设置为432px在缓存刷新时,top style属性设置为299px

        $("#dialog").dialog({
            autoOpen: true,
            modal: true,
            show: "blind",
            hide: "blind",
            width: 550,
            resizable: false,
            draggable: false,
            closeOnEscape: false,
            open: function (event, ui) {
                $(".ui-dialog-titlebar-close", ui.dialog | ui).hide().focus();
            }
        });

<div id="dialog" title="Modules">
    <br />
    <a href="@Url.Action("PopFit", "Dashboard", new { id = 1 })">
        <img src="../Content/Images/Graphics/popfit white.png" autofocus="false" alt="PopFit" style="width:100%"/>
    </a>
    <br />
    <br />
    <a href="@Url.Action("PopAudit", "Dashboard", new { id = 2 })">
        <img src="../Content/Images/Graphics/popaudit white.png" alt="PopAudit" style="width:100%"/>
    </a>
</div>

I've tried multiple things I've found on here such as adding 我已经尝试了多种在这里找到的东西,例如添加

top: ((window.innerHeight/2) - ($('#dialog').height()/2))+'px', left:((window.innerWidth/2) - ($('#dialog').width()/2))+'px' 顶部:((window.innerHeight / 2)-($('#dialog')。height()/ 2))+'px',左:(((window.innerWidth / 2)-($('#dialog' ).WIDTH()/ 2))+ '像素'

Or adding a position array with x and y coordinates but they haven't had any affect. 或添加具有x和y坐标的位置数组,但它们没有任何影响。

There is no css code attached to this dialog box. 此对话框没有附加的CSS代码。

Is there a way that i code automatically have the page load while clearing the cache as I believe this might fix the problem. 我有没有办法在清除缓存的同时自动加载页面代码,因为我相信这可以解决问题。

Any help is appreciated, Thanks 任何帮助表示赞赏,谢谢

It's this wat you want? 你想要的是这水吗?

 $("#dialog").dialog({ autoOpen: true, modal: true, show: "blind", hide: "blind", width: 550, resizable: false, draggable: false, closeOnEscape: false, open: function (event, ui) { $(".ui-dialog-titlebar-close", ui.dialog | ui).hide().focus(); } }); 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div id="dialog" title="Modules"> <br /> <a href="@Url.Action("PopFit", "Dashboard", new { id = 1 })"> <img src="../Content/Images/Graphics/popfit white.png" autofocus="false" alt="PopFit" style="width:100%"/> </a> <br /> <br /> <a href="@Url.Action("PopAudit", "Dashboard", new { id = 2 })"> <img src="../Content/Images/Graphics/popaudit white.png" alt="PopAudit" style="width:100%"/> </a> </div> 

Position 位置

Type: Object Default: { my: "center", at: "center", of: window } 类型:对象默认值:{my:“ center”,at:“ center”,of:window}

Specifies where the dialog should be displayed when opened. 指定打开对话框时应显示的位置。 The dialog will handle collisions such that as much of the dialog is visible as possible. 该对话框将处理碰撞,以使尽可能多的对话框可见。

The of property defaults to the window, but you can specify another element to position against. of属性的默认值是窗口,但是您可以指定另一个要定位的元素。 You can refer to the jQuery UI Position utility for more details about the available properties. 您可以参考jQuery UI Position Utility以获取有关可用属性的更多详细信息。 Code examples: 代码示例:

Initialize the dialog with the position option specified: 使用指定的position选项初始化对话框:

$( ".selector" ).dialog({
  position: { my: "left top", at: "left bottom", of: button }
});

For mor information use the link: http://api.jqueryui.com/dialog/#option-position 有关更多信息,请使用链接: http : //api.jqueryui.com/dialog/#option-position

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM