2009-10-03 69 views
0

嘿我一直在努力幾個小時,我不明白爲什麼以下不適用於IE瀏覽器,但其他作品。 我遇到的問題是父鏈接的背景,這是一個id分配的跨度,不會爲通過CSS設置的背景圖像設置動畫。我得到那個說「未定義」爲空或不是一個對象jQuery的動畫背景位置不工作在IE

$('a.inactive').click(function(self) { 
     var parent = $(this).parent(); 
     if (parent.css('background-position-x')) { 
      var pos = parseInt(parent.css('background-position-x').split(' ')[0]); 
     } else { 
      var pos = parseInt(parent.css('background-position').split(' ')[0]); 
     }; 
     $.ajax({ 
      type: "GET", 
      url: "somepage.php", 
      data: "id="+parent.attr('id').replace('inactive-',''), 
      complete: function(){ 
      //alert("Data Saved: "); 
       if(pos < 0) { 
        parent.animate({backgroundPosition: '(0px 0px)'}, {duration:600}); 
       } else { 
        parent.animate({backgroundPosition: '(-39px 0px)'}, {duration:600}); 
       } 

       //parent.attr('class',$(this).className.replace(/sprite-hover-(\w+)-off/gi,'active1')); 
      }, 
      async: false 
     }); 
    }); 

下面的代碼是從亞歷山大·法卡斯錯誤

(function(jQuery){ 
     $.extend($.fx.step,{ 
      backgroundPosition: function(fx) { 
      if (fx.state === 0 && typeof fx.end == 'string') { 
       var start = $.curCSS(fx.elem,'backgroundPosition'); 
       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]]; 
         } 
      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]; 

      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]]; 
      } 
     } 
     }); 
})(jQuery); 
+0

錯誤報告的是哪一行? – JohnFx 2009-10-03 20:29:22

+0

PlugIn已被修復,現在它甚至支持IE7: http://stackoverflow.com/questions/11742805/extension-of-the-backgroundposition-in-the-function-animate-dosent-work-in - 即/ 12132391#12132391 – 2012-11-22 15:58:16

回答