First, in the middle of the display; (Reference: sky100articles1790515)
Copy Code code as follows:
. ordersearchdivcss
{
Position:absolute;
z-index:100;
Display:block;
Background-color: #6ec1df;
}
<div class= "Ordersearchdivcss" id= "Divmain" style= "width:400px"; height:200px "align=" center "></div>
Js Code
Call: <input type= "button" id= "Button1" onclick= "SC1 (' Divmain ')"/>
The JScript file gets the function of the object through the element ID
function $ (ID)
{
return document.getElementById (ID);
}
Copy Code code as follows:
function Sc1 (divid) {
var Div = $ (divid);
$ (divid). Style.top = (Document.documentElement.scrollTop + (Document.documentElement.clientHeight-$ (divid). offsetheight)/2) + "px";
$ (divid). Style.left = (Document.documentElement.scrollLeft + (Document.documentElement.clientWidth-$ (divid). offsetwidth)/2) + "px";
Alert ($ (divid). Style.top);
}
second, always in the middle of the display, scrolling, in JS Add the following code:
Copy Code code as follows:
function Scall () {
SC1 ("Divmain");
}
Window.onscroll = Scall;
Window.onresize = Scall;
Window.onload = Scall;