我在这里创建了一个 fiddle :http://jsfiddle.net/surfjam/zWWpz/
我不明白为什么 animate 在两个实例中起作用,但在另一个实例中不起作用。在控制台中,错误显示“...没有方法'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');
});
});
解决方案:
感谢以下建议,我已经重新处理了问题行,如下所示:
var myId = $(this).parents('div:eq(0)').attr('id');
$('#' + myId).animate({
height: '110%',
left: '0',
top: '0',
width: 110%
}, 'fast');
感谢您的帮助!
最佳答案
attr('id')
返回一个字符串,因此您不再拥有链接的 jQuery 对象。
关于javascript - 为什么对象 [ID] 没有方法 'Animate' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9762258/