1. display in the middle. (See: sky100articles1790515)
Copy codeThe Code is 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')"/>
// Functions of the object obtained by element id in the JScript File
Function $ (id)
{
Return document. getElementById (id );
}Copy codeThe Code is as follows: function sc1 (DivId ){
Var Div =$ (DivId );
$ (DivId). style. top = (document.doc umentElement. scrollTop + (document.doc umentElement. clientHeight-$ (DivId). offsetHeight)/2) + "px ";
$ (DivId). style. left = (document.doc umentElement. scrollLeft + (document.doc umentElement. clientWidth-$ (DivId). offsetWidth)/2) + "px ";
// Alert ($ (DivId). style. top );
}
2. Always display in the middle. When scrolling, add the following code in Js:
Copy codeThe Code is as follows: function scall (){
Sc1 ("DivMain ");
}
Window. onscroll = scall;
Window. onresize = scall;
Window. onload = scall;