CSS+JS蒙板居中技術、居中技術、JSを使ってdivの幅の高さを取得しますか?
3075 ワード
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<title>CSS+JS </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<style>
// : CSS+JSS
#mb {
position:absolute;
background:#000;filter:alpha(opacity=30);
z-index:99;
margin:0 auto;
padding:0;
left:0;
top:0;
width:100%;
height:100%;
}
#wd {
position:absolute;
margin:0 auto;
padding:0;
top:25%;
z-index:100;
background:#fff;
}
</style>
</head>
<body>
<div id = "mb" name = "mb" style="display:none;"></div>
<div id ="wd" name = "wd" style="display:none;"><img src ="1.jpg"></img></div>
<input type="button" onclick="controlDiv('wd',1)" value=" " />
<iframe id="" src="http://www.baidu.com" width="100%" height="300"></iframe>
<script type="text/javascript">
function controlDiv(DivID,divCase){
var mengban = document.getElementById("mb");
var divs=document.getElementById(DivID);
// : JS div
// 399 div
var v_left=(document.body.clientWidth-399)/2 + document.body.scrollLeft;
var v_top=(document.body.clientHeight-divs.clientHeight)/2 + document.body.scrollTop;
if(divCase==1){
divs.style.left=v_left+'px';
divs.style.top=v_top+'px';
divs.style.display="block";
mengban.style.display="block";
// : JS DIV
//js div
//alert("divs.clientWidth--->"+divs.clientWidth);
//alert("divs.clientHeight--->"+divs.clientHeight);
//alert("divs.scrollWidth--->"+divs.scrollWidth);
//alert("divs.scrollHeight--->"+divs.scrollHeight);
//alert("divs.offsetWidth--->"+divs.offsetWidth);
//alert("divs.offsetHeight--->"+divs.offsetHeight);
}else if(divCase==2){
divs.style.display="none";
mengban.style.display="none";
}
else
divs.innerHTML=divCase; // HTML DIV
}
</script>
</body>
</html>