您的位置:首页 > Web前端 > CSS

设置外部样式坐标的位置

2013-11-16 13:21 363 查看
<style type="text/css">
#main{text-align:center; background-color:#9FF; height:600px;width:800px}
#adver{
position:absolute;
left:50px;
top:30px;
z-index:2;
}

</style>
<script src="js/scroll.js"></script>
</head>
<body>
<div id="adver"><img src="images/adv.jpg"/></div>

<div id="testDiv" style="position:absolute;left:300px;top:50px;background-color:red; width:80px; height:200px">内部样式的div</div>

<input   type="button"   value="测试外部样式坐标位置" onClick="test('adver')"/>

<div id="main">网页内容</div>
</body>


function test (divID){
var divObj=document.getElementById(divID);

var leftValue,leftValue;

//alert(    .appName);   //使用navigator判断有时不准确,例如:在FF下运行判断为Netscape

if(divObj.currentStyle){  //IE
leftValue=divObj.currentStyle.left;
topValue=divObj.currentStyle.top;
}else{  //FF
leftValue=document.defaultView.getComputedStyle(divObj,null).left;
topValue=document.defaultView.getComputedStyle(divObj,null).top;
}

alert("left="+leftValue+"\ntop="+topValue);
divObj.style.left=parseInt(leftValue)+200+"px";
divObj.style.top=parseInt(topValue)+100+"px";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐