SoFunction
Updated on 2025-04-09

Always display the code of Div in the middle of the screen (css+js)

1. Display in the middle; (reference:sky100articles1790515)
Copy the codeThe code is as follows:

.ordersearchDivCss
{
position: absolute;
z-index: 100;
display: block;
background-color: #6ec1df;
}
<div class="ordersearchDivCss" style="width: 400px; height:200px" align="center"></div>

Js code
Call: <input type="button" onclick="sc1('DivMain')" />
// JScript file. Functions that obtain object through element id
function $(id)
{
return (id);
}
Copy the codeThe code is as follows:

function sc1(DivId) {
var Div = $(DivId);
$(DivId). = ( + ( - $(DivId).offsetHeight) / 2) + "px";
$(DivId). = ( + ( - $(DivId).offsetWidth) / 2) + "px";
//alert($(DivId).);
}

2. Always display in the middle. When scrolling, add the following code to Js:
Copy the codeThe code is as follows:

function scall() {
sc1("DivMain");
}
= scall;
= scall;
= scall;