화면 중간에 항상 Div 코드 표시(css+js)

1268 단어
1. 중간에 표시하기;(참조:sky100articles1790515)
 
  
.ordersearchDivCss
{
position: absolute;
z-index: 100;
display: block;
background-color: #6ec1df;
}


Js code
调用:
// JScript 文件 通过元素id得到对象的函数
function $(id)
{
return document.getElementById(id);
}
 
  
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. 항상 중간에 표시하고 스크롤할 때 Js에 다음 코드를 추가합니다.
 
  
function scall() {
sc1("DivMain");
}
window.onscroll = scall;
window.onresize = scall;
window.onload = scall;

좋은 웹페이지 즐겨찾기