问下最后一个fn方法怎么实现不了,还报错
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>js动态</title>
<style>
*{
padding:0;
margin:0;
}
html,body{
width:100%;
height:100%;
}
li{
list-style:none;
width:200px;
height:100px;
display:block;
background-color:#0f0;
margin-top:20px;
border:2px solid #f00;
font-size:14px;
opacity:0.3;
filter:alpha(opacity:30);
}
</style>
</head>
<body>
<ul>
<li>fontsize</li>
<li>fontsize</li>
<li>fontsize</li>
</ul>
<script>
window.onload = function(){
var oLi = document.getElementsByTagName("li");
for(var i=0;i<oLi.length;i++){
oLi[i].timer =null;
oLi[i].onmouseover = function(){
var g =this;
starMouse(this,{width:400,opacity:100},function(){
starMouse(this,{color:#f00})
});
}
oLi[i].onmouseout =function(){
starMouse(this,{width:200,opacity:30});
}
}
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
function starMouse(obj,json,fn){
var flag =true;
clearInterval(obj.timer);
var icur = 0;
obj.timer = setInterval(function(){
for(var attr in json){
if(attr=="opacity"){
icur = Math.round(parseFloat(getStyle(obj,attr)*100));
}else{
icur =parseInt(getStyle(obj,attr));
}
var pend = (json[attr]-icur)/8;
pend = pend>0?Math.ceil(pend):Math.floor(pend);
if(icur!=json[attr]){
flag=false;
}
if(attr=="opacity"){
obj.style.filter ='alpha(opacity:'+(icur+pend)+')';
obj.style.opacity=(icur+pend)/100;
}else{
obj.style[attr] = parseInt(getStyle(obj,attr))+pend+"px";
}
}
if(flag){
clearInterval(obj.timer);
if(fn){
fn();
}
}
},30)
}
</script>
</body>
</html>