<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>offset的bug</title>
<style>
/*#div1{ width:200px; height:200px; background:yellow;}
#div1{height:200px; background:yellow; border:1px solid #000;}*/
#div1{ width:200px; height:200px; background:yellow; border:1px solid #000;}
</style>
<script>
function getStyle(obj, name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
return getComputeredStyle(obj, false)[name];
}
}
setInterval(function(){
var oDiv=document.getElementById('div1');
//oDiv.style.width=oDiv.offsetWidth-1+'px';
//oDiv.style.width=parseInt(oDiv.style.width)-1+'px';
oDiv.style.width=parseInt(getStyle(oDiv, 'width'))-1+'px';
},30);
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
offset的bug_只兼容IE
最新推荐文章于 2021-06-09 14:27:30 发布