jquery animate:如何动态获取动画元素的高度?
如何为 animate()
动态获取元素的高度?
这是我的代码,用于显示元素中更多隐藏的文本。问题是我必须将动画高度(例如 300px)固定为固定数字,并且文本不断变化,所以我不知道它会多长。
$('.toggle-slide').click(function() {
var object = $(this);
var object_target = $('.text-about');
var target_height = object_target.height();
object_target.animate({
height:'300px'
}, 1500 );
return false;
});
所以我认为应该动态获取元素的实际高度,然后我可以将此参数传递给animate()
。
但是我怎样才能得到这个动态高度呢?
或者也许您还有其他更好的想法?
这是我的测试链接。
How can I get the height of element dynamically for animate()
?
This is my code to reveal more hidden text in an element. The problem is that I have to fix the animate height (300px for instance) to a fixed number and the text is constantly changed so I don't know how long it will be.
$('.toggle-slide').click(function() {
var object = $(this);
var object_target = $('.text-about');
var target_height = object_target.height();
object_target.animate({
height:'300px'
}, 1500 );
return false;
});
So I think the actual height of the element should be obtained dynamically then I can pass this parameter into animate()
.
But how can I get this dynamic height?
Or maybe you have other better ideas?
Here is my testing link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我让它工作起来,首先让它全部可见,然后获取高度,然后放回 200px 并设置动画:)
在较慢的机器上可能会闪烁,但这是一个想法
I got it to work by first making it all visible, then taking the height, then putting back to 200px and animating :)
maybe a flicker on slower machines but its an idea