javascript 获取浏览中的网页的中心轴..急急急
1个回答
展开全部
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var geometry={};
if(window.innerWidth){
geometry.getViewportWidth=function(){
return window.innerWidth;
}
}else if(document.documentElement && document.documentElement.clientWidth){
geometry.getViewportWidth=function(){
return document.documentElement.clientWidth;
}
}else if(document.body.clientWidth){
geometry.getViewportWidth=function(){
return document.body.clientWidth;
}
}
function change(){
document.getElementById('test').style.left=geometry.getViewportWidth()/2+'px';
}
window.onload=function(){
change();
window.onresize=function(){
change()
}
}
</script>
</head>
<body>
<div id="test" style="height:500px; font-size:12px;border-left:solid 2px red; position:absolute; left:0; top:20px"><span style="margin:20px 0 0 5px">中心轴在这儿</span></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var geometry={};
if(window.innerWidth){
geometry.getViewportWidth=function(){
return window.innerWidth;
}
}else if(document.documentElement && document.documentElement.clientWidth){
geometry.getViewportWidth=function(){
return document.documentElement.clientWidth;
}
}else if(document.body.clientWidth){
geometry.getViewportWidth=function(){
return document.body.clientWidth;
}
}
function change(){
document.getElementById('test').style.left=geometry.getViewportWidth()/2+'px';
}
window.onload=function(){
change();
window.onresize=function(){
change()
}
}
</script>
</head>
<body>
<div id="test" style="height:500px; font-size:12px;border-left:solid 2px red; position:absolute; left:0; top:20px"><span style="margin:20px 0 0 5px">中心轴在这儿</span></div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询