為什么執(zhí)行完后 不能復(fù)原寬度 ,透明度可以。
function startMove(obj, attri,iTarget,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
? ? ? ? ? ? var ic=0;
? ? ? ? ? ? ? ? ? if (attri=="opactiy") {
? ? ? ? ? ? ? ? ? ic=Math.round(parseFloat(getStyle(obj,attri))*100)
? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? else{
? ? ? ? ?ic=parseInt(getStyle(obj,attri))
? ? ?}
? ? ? ? ? ? ? var speed=(iTarget-ic)/10;
? ? ? ? ? ? ? speed=speed>0?Math.ceil(speed):Math.floor(speed);
? ? ? ? ? ? ? if (ic==iTarget) {
? ? ? ? ? ? ? clearInterval(obj.timer);
? ? ? ? ? ? ? if (fn) {
? ? ? ? ? ? ? fn();
? ? ? ? ? ? ? }
? ? ? ? ? ? ? }
? ? ? ? ? ? ? else{
? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ? if(attri=='opacity'){
obj.style.opacity = (ic+speed)/100;
obj.style.filter='alpha(opacity:'+(ic+speed)+')';
} ?
? ? ? ? ? ? ? else{
? ? ? ? ? ? ? obj.style[attri]=ic+speed+'px';
? ? ? ? ? ? ? }
? ? ? ? ?}
},50)
}
?function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];//針對ie瀏覽器。
}else{
return getComputedStyle(obj,false)[attr];//針對firefox瀏覽器。
}
}
window.onload = function(){
var Li1=document.getElementById('li1');
Li1.onmousemove=function(){
startMove(Li1,'width',300,function(){
startMove(Li1,'opacity',500);
});
}
Li1.onmouseout=function(){
startMove(Li1,'opacity',200,function(){
startMove(Li1,'width',100);
})
}
}
2016-06-11
應(yīng)該是亮度超出了,opacity值的范圍應(yīng)該是0-100,你的值設(shè)置100-500太大了,改成0-100這個范圍就好了