2012-04-12 69 views
0

我試圖找到一種方法,使用下面的jQuery插件(by Alexander Farkas)動畫我的身體的背景位置:動畫效果背景位置在IE拋出錯誤8

(function($) { 
    if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8 
     var oldCurCSS = $.curCSS; 
     $.curCSS = function(elem, name, force){ 
      if(name === 'background-position'){ 
       name = 'backgroundPosition'; 
      } 
      if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){ 
       return oldCurCSS.apply(this, arguments); 
      } 
      var style = elem.style; 
      if (!force && style && style[ name ]){ 
       return style[ name ]; 
      } 
      return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force); 
     }; 
    } 

    var oldAnim = $.fn.animate; 
    $.fn.animate = function(prop){ 
     if('background-position' in prop){ 
      prop.backgroundPosition = prop['background-position']; 
      delete prop['background-position']; 
     } 
     if('backgroundPosition' in prop){ 
      prop.backgroundPosition = '('+ prop.backgroundPosition; 
     } 
     return oldAnim.apply(this, arguments); 
    }; 

    function toArray(strg){ 
     strg = strg.replace(/left|top/g,'0px'); 
     strg = strg.replace(/right|bottom/g,'100%'); 
     strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2"); 
     var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/); 
     return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]]; 
    } 

    $.fx.step. backgroundPosition = function(fx) { 
     if (!fx.bgPosReady) { 
      var start = $.curCSS(fx.elem,'backgroundPosition'); 
      if(!start){//FF2 no inline-style fallback 
       start = '0px 0px'; 
      } 

      start = toArray(start); 
      fx.start = [start[0],start[2]]; 
      var end = toArray(fx.end); 
      fx.end = [end[0],end[2]]; 

      fx.unit = [end[1],end[3]]; 
      fx.bgPosReady = true; 
     } 
     //return; 
     var nowPosX = []; 
     nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0]; 
     nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];   
     fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1]; 

    }; 
})(jQuery); 

其實,它說,這是從兼容IE6 +,但執行該時:

$('body').stop().animate({backgroundPosition: '50% -800px'}, 2000); 

..它拋出IE8或以下錯誤消息較低版本:

財產「1」沒有檢索到的值:對象要麼是空或未定義

什麼referrs這條線上面的插件:

return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]]; 
+0

請郵寄僅與工作崗位相關的 – Starx 2012-04-12 05:56:06

+0

這些代碼@Starx這些都是爲了瞭解或發現的問題,在我看來,所有相關的代碼.. – 2012-04-12 06:01:01

回答

0

它僅僅是Internet Explorer 8中,處理腳本不同和投擲errorss,如:

No retrieved value for property "1": The object either is null or undefined