2012-03-18 107 views
0

我已經在這裏創造一個小提琴:http://jsfiddle.net/surfjam/zWWpz/爲什麼Object [ID]沒有方法'Animate'?

我想不通,爲什麼在兩種情況下的動畫作品,但不是在另一個。在控制檯錯誤說「......沒有方法‘動畫’......」

jQuery(document).ready(function($) { 

    var effect = "inm-shine"; 

    $(".circle-button-border").mouseenter(function() { 

     $(this).addClass(effect); 

     $(this).stop(true, true).animate({ 
      opacity: '0.85' 
     }, 'slow').css({ 
      'z-index': '100', 
      top: '0', 
      left: '0' 
     }); 

//Error coming from this line... 

     $(this).parents('div:eq(0)').attr('id').animate({ 
      height: '120%', 
      left: '0', 
      top: '0', 
      width: '120%' 
     }, 'fast'); 

    }).mouseleave(function() { 
     $(this).animate({ 
      opacity: '0' 
     }, 'fast'); 
    }); 
});​ 

SOLUTION:

多虧了下面的建議,我已經修改了問題行是這樣的:

var myId = $(this).parents('div:eq(0)').attr('id'); 
     $('#' + myId).animate({ 
      height: '110%', 
      left: '0', 
      top: '0', 
      width: 110% 
     }, 'fast'); 

感謝您的幫助!

+0

'attr('id')'返回* id *屬性的值。 – Gumbo 2012-03-18 21:03:52

+0

來自gumbo的評論是正確的。你試圖對不在jquery對象上的字符串進行動畫處理。 – 2012-03-18 21:05:19

回答

6

attr('id')正在返回一個字符串,所以你不再擁有鏈式jQuery對象。

相關問題