jquery:有没有办法在渲染之前猜测高度?
这是我的代码:
- 首先,我分配一些 htm 代码,其中有一个表格。
- (表格不可见)
- 然后我转储高度:每行都是 0。
- 然后我 fadeIn() 表格,
- 然后转储高度:每行为 320px。
你知道我如何在渲染之前计算高度吗?
我的目标是,如果行的高度太大,则“剪切”行中的一些信息。
$('#tableau').html(htm);
$('.tableau tr td').each(function() {
console.log($(this).height());
} );
$('#wait').queue(function() {
$('#tableau').fadeIn(100).queue(function() {
$('.tableau tr td').each(function() { console.log($(this).height()); } );
}
);
});
我知道这听起来像这里但这不是完全相同的问题。
谢谢你!
Here's my code:
- First I assign some htm code where there's a table in it.
- (the table is not visible)
- then I dump the height: it is 0 for each row.
- then I fadeIn() the table
- then I dump the height: it is 320px for each row.
Have you any idea how I could do to compute height before rendering?
My goal is to "cut" some information in the rows if their height is too big.
$('#tableau').html(htm);
$('.tableau tr td').each(function() {
console.log($(this).height());
} );
$('#wait').queue(function() {
$('#tableau').fadeIn(100).queue(function() {
$('.tableau tr td').each(function() { console.log($(this).height()); } );
}
);
});
I know it sounds like here but it's not exactly the same problem.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在渲染之前不可能获取
高度
。您有三个选择:max-height: 100px
(示例)添加到元素的选择器中。It's not possible to get the
height
before rendering. You've got three options:max-height: 100px
(example) to the selector of your element.您可以尝试将内容渲染到屏幕外,使其不可见。因此将其放在绝对定位的div中,并将其向左移动10,000像素。然后渲染,并检查每个的高度。内容仍在渲染中,因此不完全满足您的要求,但它不会可见。然后您可以进行调整,最后将内容移动到屏幕上。
You might try rending the content offscreen, where it's not visible. So put it in a div that is positioned absolutely, and move it left 10,000 pixels. Then render, and check the height of each. The content is still being rendered so it doesn't fully meet your requirement, but it won't be visible. You can then adjust, and finally move the content onto the screen.