Home  >  Article  >  Web Front-end  >  Always display Div code in the middle of the screen (css js)_javascript tips

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

WBOY
WBOYOriginal
2016-05-16 18:09:491455browse
1. Display in the middle; (Reference: sky100articles1790515)
Copy code Code As follows:

.ordersearchDivCss
{
position: absolute;
z-index: 100;
display: block;
background-color: #6ec1df;
}


Js code
Call:
// JScript file gets the object's function through the element id
function $(id)
{
return document.getElementById(id);
}
Copy code The code is 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);
}

2. Always display in the middle, scroll When, add the following code in Js:
Copy code The code is as follows:

function scall() {
sc1("DivMain");
}
window.onscroll = scall;
window.onresize = scall;
window.onload = scall;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn