為什么CHROME報(bào)錯(cuò)說(shuō)Uncaught TypeError: Cannot read property 'currentStyle' of undefined
function getStyle(obj,attr) {
if (obj.currentStyle) {
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
? ? }
}
function startMove(obj,json,fn) {
var flag = true ;?
clearInterval(obj.timer);
obj.timer=setInterval(function () {
for(var attr in json) {
//取當(dāng)前值
var icur = 0;
if(attr=='opacity') {
icur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
icur=parseInt(getStyle(obj.attr));
}
//計(jì)算速度
var ispeed=(json[attr]-icur)/8;
ispeed=ispeed>0?Math.ceil(ispeed):Math.floor(ispeed);
//檢測(cè)停止
if(icur!=json[attr]) {
flag=false;
}
if(attr=='opacity') {
? ? ? ? ? ? ? ? obj.style.filter='alpha(opacity:'+(icur+ispeed)+')';
? ? ? ? ? ? ? ? obj.style.opacity=(icur+ispeed)/100;
}
? ? ? ? ? ? else{
? ? ? ? ? ? obj.style[attr]=icur+ispeed+'px';
? ? ? ? ? ? } ? ?
}
if(flag){
? ? ? ? ? ? clearInterval(obj.timer);
? ? ? ? ? ? if(fn){
? ? ? ? ? ? fn();
? ? ? ? ? ? }
? ? ? ? ? ? }
},30);
}
2016-04-20
不知道,我有沒(méi)有看錯(cuò);
obj.attr 而不是obj, attr;?
點(diǎn)和逗號(hào);
一個(gè)傳參數(shù),一個(gè)查屬性