可以帮忙看下代码吗
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
div {
width: 1000px;
height: 300px;
background: #0e90d2;
filter: alpha(opacity:30);
opacity: 0.3
}
</style>
</head>
<body>
<div>
</div>
<script type="text/javascript">
window.onload = function () {
var oDiv = document.getElementsByTagName('div')[0],
timer = null;
oDiv.onmouseover = function () {
startMove('opacity',100);
}
oDiv.onmouseout = function () {
startMove('opacity',30);
}
}
function startMove(attr,iTarget) {
clearInterval(timer);
timer = setInterval(function(){
var oDiv = document.getElementsByTagName('div')[0],
var icur=0;
if(attr=='opacity'){
icur=Math.round(parseFloat(getStyle(oDiv,attr))*100);
}
else{
icur=parseInt(getStyle(oDiv,attr));
}
var speed=(iTarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==iTarget){
clearInterval(timer);
}
else{
if(attr=='opacity'){
icur+=speed;
oDiv.style.filter='alpha(opacity:'+icur+')';
oDiv.style.opacity=icur/100;
}
else{
oDiv.style[attr]=icur+speed+'px'
}
}
}, 30)
}
//获取css样式
function getStyle(obj, attr) {
if (obj.currentStyle) {
return obj.currentStyle[attr];
}
else {
return getComputedStyle(obj, null)[attr];
}
}
</script>
</body>
</html>
如加入obj参数 则
oDiv.onmouseover = function () {
startMove(this,'opacity',100);
}
在这里 我不用obj的参数可以么 直接默认为oDiv 不知道是不是这个原因?