在转换完成之前获取div的转换后偏移量

时间:2014-09-11 16:01:12

标签: javascript jquery html css css3

我有一个包含多行框的页面。单击一个框时,它会扩展高度和宽度,如果是最后一个,有时会将其向下推。盒子有一个.4s转换。

我希望在转换发生时滚动到新位置。只需使用setTimeout即可轻松完成转换。

    setTimeout(function() {
        var divHeight = box.offset().top - 40;
        $('html,body').animate({
            scrollTop: divHeight
        }, 400);
    }, 400);

有没有办法在转换完成之前获取盒子的新位置?

完整代码

$('.expand-button').click(function() {
    var boxContent = $(this).parent();
    var box = boxContent.parent();

    $('.box').removeClass('selected');
    $('.box-content').removeClass('selected');      
    box.addClass('selected');       
    boxContent.addClass('selected');
    $container.isotope();
    setTimeout(function() {
        var divHeight = box.offset().top - 40;
        $('html,body').animate({
            scrollTop: divHeight
        }, 400);
    }, 400);

});

0 个答案:

没有答案
相关问题