為什么CHROME報錯說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) {
//取當前值
var icur = 0;
if(attr=='opacity') {
icur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
icur=parseInt(getStyle(obj.attr));
}
//計算速度
var ispeed=(json[attr]-icur)/8;
ispeed=ispeed>0?Math.ceil(ispeed):Math.floor(ispeed);
//檢測停止
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
不知道,我有沒有看錯;
obj.attr 而不是obj, attr;?
點和逗號;
一個傳參數,一個查屬性