fn的透明度 报错 并且没有变化
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 100px;
height: 100px;
background: blueviolet;
}
</style>
<script src="startmove.js"></script>
<script>
window.onload=function () {
var ax1=document.getElementsByTagName('div');
for (var i=0;i<ax1.length;i++){
ax1[i].onmouseover=function () {
startMove(this,{width:200,height:200},function () {
startMove(this,{opacity:30})
});
};
ax1[i].onmouseout=function () {
startMove(this,{width:100,height:100})
}
}
}
</script>
</head>
<body>
<div id="li"></div>
<div></div>
<div></div>
</body>
</html>
function startMove(obj,json,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function () {
var flg =true; //假设所有动作已经完成
for (var attr in json) {
//获取当前值
var icur = 0;
if (attr == 'opacity') {
icur = Math.round(parseFloat(getStyle(obj, attr)) * 100);
}
else {
icur = parseInt(getStyle(obj, attr));
}
//算速度
var speed = 0;
speed = (json[attr] - icur) / 8;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
//检测停止
if (icur != json[attr]) {
flg=false;
}
if (attr == 'opacity') {
//针对IE浏览器
obj.style.filter = 'alpha(opacity:' + (icur + speed) + ')';
//针对其他
obj.style.opacity = (icur + speed) / 100;
}
else {
obj.style[attr] = icur + speed + 'px';
}
}
if (flg){
clearInterval(obj.timer);
if (fn){
fn()
}
}
},30)
}
function getStyle(obj,attr){
if (obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}