简体   繁体   English

javascript覆盖居中对齐的模式弹出窗口

[英]javascript to overlay a modal popup that is center aligned

want to know Simply the javascript to overlay a div on centre of the page. 想知道的简单javascript将div覆盖在页面中心。

Just want to use plain java script to show and hide a div on the center of the page with "Please wait..." message and disable the background. 只想使用普通的Java脚本来显示和隐藏带有“请稍候...”消息的div 并禁用背景。 Also this div shoud show on top of the other content of the page. 此div也应显示在页面其他内容的顶部。

My div looks like this 我的div看起来像这样

<div id='mydiv' style="display:none;" ><img src="myimg.gif" /> Please Wait... </div>

On click of a button , I want to show the div content center aligned on the page. 单击一个按钮,我想显示在页面上对齐的div内容中心。

I do not want to use jquery,extjs,,etc to achieve this. 不想使用jquery,ExtJS的,,等,以实现这一目标。

I have seen a few examples on the web with lot of other features added to a modal popup, just looking for something simple and clean.The bare minimum JS required to do this. 我在网上看到了一些示例,这些示例在模式弹出窗口中添加了许多其他功能,只是在寻找简单,干净的东西,而这样做所需的最低限度的JS。

The div you want to display needs to have an ID: 您要显示的div需要具有一个ID:

<div id="loaderdiv">

Then in your javascript, you display this div with the following code: 然后在您的JavaScript中,使用以下代码显示该div:

document.getElementById("loaderdiv").style.display = '';

Thats the bare minimum you'll need. 那就是您所需要的最低限度。

Centering the image can be done using CSS: 可以使用CSS将图片居中:

<div style="position:absolute;top:50%;left:50%;margin-top:-[imgheight/2]px;margin-left:-[imgwidth/2]px">
<div class="overlay_msg" id="overlay_msg" style="width:350px; height:100px; background-color:#ffffff; margin-left:300px; margin-top:20%; visibility:hidden; z-index:201; position:fixed; padding:15px; text-align:center;">
                <a href="http://example.com">example.com</a><br />
        </div><!--overlay_msg-->
        <div class="my_overlay" id="my_overlay" style="background-color:#000000; opacity:.7; position:fixed; z-index:200; width:100%; height:100%; margin:0px; padding:0px; visibility:hidden;" onclick="hideMyOverlay()">
        </div><!--my_overlay-->
        <script type="text/javascript">
            function showMyOverlay()
            {
                document.getElementById('my_overlay').style.visibility='visible';
                document.getElementById('overlay_msg').style.visibility='visible';
            }
            function hideMyOverlay()
            {
                document.getElementById('my_overlay').style.visibility='hidden';
                document.getElementById('overlay_msg').style.visibility='hidden';               
            }
        </script>

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

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