为什么距离浏览器边框出来这么多?用的老师的move.js
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
*{margin:0;padding:0;}
#div1{
width:200px;
height:200px;
background:#cd0000;
position:relative;
left:-200px;
top:0;
}
#div1 span{
color:#fff;
width:20px;
height:50px;
background:#cd0000;
position:absolute;
left:200px;
top:60px;
padding-top: 15px;
}
</style>
<script>
window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function(){
startMove(oDiv,'left',0);
}
oDiv.onmouseout=function(){
startMove(oDiv,'left',-200);
}
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}// 获取任意属性至,针对IE与火狐做不同的处理 currentStyle是IE方法 Computed Style是火狐的方法
//==写错,很难发现错误
function startMove(obj,attr,iTarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var icur=0;//取当前值
if(attr=='opacity'){
icur=Math.round(parseFloat(getStyle(obj,attr))*100)
}
else{
icur=parseInt(getStyle(obj,attr));
}
//算速度
var speed=(iTarget-icur)/8
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//检测停止
if(icur==iTarget){
clearInterval(obj.timer);
}
else{
if(attr=='opacity'){
obj.style.filter='alpha:(opacity:'+icur+speed+')';
obj.style.opacity=(icur+speed)/100;
}
else{
obj.style[attr]=icur+speed+'px';
}
}
},30)
}
</script>
</head>
<body>
<div id="div1">
<span class="share">分享</span>
</div>
</body>
</html>