为什么Object[ID]没有方法'制作动画'

Why Object [ID] has no method 'Animate'?

本文关键字:动画 有方法 Object ID 为什么      更新时间:2023-09-26

我在这里创建了一个小提琴:http://jsfiddle.net/surfjam/zWWpz/

我不明白为什么动画在两种情况下都有效,但在另一种情况下却无效。在控制台错误说"…没有方法‘动画’…"

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');
    });
});​

解决方案:

多亏了下面的建议,我重新设计了问题行,如下所示:

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

谢谢你的帮助!

attr('id')正在返回一个字符串,因此您不再拥有链接的jQuery对象。