2014-01-23 28 views
0

嗨正嘗試使用以下的過濾器過濾器爲空或不是一個對象

所以我有這個功能,其設置角度

var setElementAngle=function(ele,ang){ 
    var angle = Math.PI/ang; 

    costheta = Math.cos(angle); 
    sintheta = Math.sin(angle); 

    ele.filters.item(0).M11 = costheta; 
    ele.filters.item(0).M12 = -sintheta; 
    ele.filters.item(0).M21 = sintheta; 
    ele.filters.item(0).M22 = costheta; 
}; 

initally我創建一個img在IE 8旋轉和圖像使用以下

var create =function (el, attr, style) { 
     this.elem = document.createElement(el); 
     for (var k in attr) { 
      if (attr.hasOwnProperty(k)) { 
       this.elem.setAttribute(k, attr[k]) 
      } 
     } 
     for (var k in style) { 
      if (style.hasOwnProperty(k)) { 
       this.elem.style[k] = style[k] 
      } 
     } 
     return this.elem 
}; 

     var _img=create('img', 
{'id':'_img','width':'50','height':'53','border':'0','src':'10fqnav.jpg'}, 
{'position':'absolute', 
'height':'53px', 
'width':'50px', 
'zIndex':'9001', 
'top':'0px', 
'right':'0px', 
'display':'inline-block', 
'filter':'progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\')' 
}); 

再後來在我的代碼我改變形象src屬性,然後嘗試轉動它

的功能元素
$('#_img').attr('src','fold_new.jpg'); 
    setElementAngle(_img,0.45); 

在這一點上,我得到以下錯誤

Message: 'filters' is null or not an object 

任何想法可能是什麼原因。也是初始化設置過濾器。

+0

@cookiemonster所以任何其他方式我可以在IE 8中旋轉圖像。我應該能夠旋轉它任何指定的角度 – nyfer

+0

創建小提琴更好的答案。 –

回答

0

_img最有可能不指向在您的通話將HTML的圖像

setElementAngle(_img,0.45); 

嘗試改變,要

setElementAngle($('#_img'),0.45); 

我猜測,在內存中的副本(即_img)在它實際上在DOM中並且必須在那裏訪問之前沒有「具有佈局」。