封装的函数都是一样的,主函数中将div换成了列表,为什么无法实现功能?
window.onload=function(){
var oli=document.getElementsByTagName("li");
for(i=0;i<oli[i].length;i++){
//oli[i].opacity=30;
oli[i].onmouseover=function(){
startmove(this,100,"opacity");
}
}
}
function startmove(obj,itarget,attr,fn){
clearInterval(obj.timer);
//var div1=document.getElementById("div1");
obj.timer=setInterval(function(){
var icur=0;
if(attr=="opacity"){
icur=Math.round(parseFloat(getstyle(obj,attr))*100);
}
else{
var 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);
if (fn){
fn();
}
}
else{
if(attr=="opacity"){
obj.style[attr]=(icur+speed)/100;
obj.style['filter']='alpha(opacity:icur+speed)';
}
else{
obj.style[attr]=icur+speed+"px";
}
}
},30)
}
function getstyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}