在 jQuery 动画期间获取实际的 div 高度

发布于 2024-11-28 03:14:16 字数 137 浏览 3 评论 0原文

我有一些动画图表。这很酷。但我需要在动画期间将 div 的当前高度写入另一个 div(如模拟计时器)。我也有起始高度和最终高度。 因此,也许一种棘手的方法是可以的,即在动画本身单独进行的同时进行连续写出。不幸的是,我也不知道这样做。 谢谢!

I have some animated graphs. It's cool. But I need to write out the current height of the div to another div during the animation (like an analogue timer). I have the starting and the final height, too.
So, maybe a tricky method is OK, where a continuous write out is happening while the animation itself, separately. Unfortunately, I have no idea to do this neither.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

屋檐 2024-12-05 03:14:16

使用记录不足的 animate step 函数 (演示):

$('#div1').animate({
    height: 500
}, {
    step: function(height) {
        $('#div2')
            .height(height)
            .html( parseInt(height,10) );
    },
    duration: 500,
    complete: function() {}
});

Use the under-documented animate step function (demo):

$('#div1').animate({
    height: 500
}, {
    step: function(height) {
        $('#div2')
            .height(height)
            .html( parseInt(height,10) );
    },
    duration: 500,
    complete: function() {}
});
勿忘初心 2024-12-05 03:14:16

使用 jquery 尝试此操作,

$("#div2").text($("#div1").height());

您必须将其附加到您的动画代码中,但由于您没有发布它,所以我无法猜到!

Try this using jquery

$("#div2").text($("#div1").height());

you'll have to append it to your animations code, but as you didn't post it I can't guess it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文