animate jQuery属性不能使用变量?

时间:2013-06-27 17:38:12

标签: javascript jquery

为每个具有不同变量的多个已加载元素声明height()个变量后,animate()函数似乎无法加载变量excHeight

excHeight使用animate()的值的最佳方法是什么?

$(".exPand a").click(function (event) {
    event.preventDefault();

    var post_id = $(this).attr("rel");

    var postHeight = $(this).closest('.boxy')
                            .find('.articleImageThumb')
                            .height();

    var excHeight = $(this).closest('boxy')
                           .find('.articleImageThumb')
                           .find('.initialPostLoad')
                           .height();

    $.ajaxSetup({cache:false});

    $(this).closest('.boxy')
           .animate({height: postHeight+excHeight}, 1000);

    $(this).closest('.boxy')
           .find('.articleImageThumb')
       .animate({top: 0}, 1000);

    $(this).closest('.boxy').find('.articleTitle')
    .animate({bottom: excHeight}, 1000);

    $(this).closest('.boxy').find('.postmetadata')
    .animate({bottom: excHeight}, 1000);
});

1 个答案:

答案 0 :(得分:4)

似乎因为忘记boxy班级名称中的“点”而无法正常工作:var excHeight = $(this).closest('boxy'),必须如下:var excHeight = $(this).closest('.boxy')