Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 18:09:49
Original
1500 people have browsed it
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;
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template