2012-03-18 108 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对象。

相关问题