admin管理员组

文章数量:1322669

want to know Simply the javascript to overlay a div on centre of the page.

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. Also this div shoud show on top of the other content of the page.

My div looks like this

<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.

I do not want to use jquery,extjs,,etc to achieve this.

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.

want to know Simply the javascript to overlay a div on centre of the page.

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. Also this div shoud show on top of the other content of the page.

My div looks like this

<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.

I do not want to use jquery,extjs,,etc to achieve this.

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.

Share Improve this question edited Jan 5, 2012 at 6:28 slugster 50k14 gold badges103 silver badges148 bronze badges asked Feb 20, 2009 at 11:06 dotnetcoderdotnetcoder 3,60110 gold badges57 silver badges82 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

The div you want to display needs to have an ID:

<div id="loaderdiv">

Then in your javascript, you display this div with the following code:

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

Thats the bare minimum you'll need.

Centering the image can be done using 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.">example.</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>

本文标签: javascript to overlay a modal popup that is center alignedStack Overflow