事件后使用 Jquery 均衡高度
我正在开发一个可以解析 RSS 提要并将其显示在一系列 div 中的网站。加载所有提要后,我想运行一个 jquery 函数,该函数基本上获取最高 div 的高度并将所有 div 设置为等于该高度。您可以在这里查看该网站: http://vitaminjdesign.com/adrian/
目前,我使用 jquery < a href="http://www.cssnewbie.com/equal-height-columns-with-jquery/" rel="nofollow">等高插件概述如下:
function equalHeight(group) {
var tallest = 0;
group.each(function() {
var thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
您可以使用以下方式调用它:
$(document).ready(function() {
$(".block").equalHeights();
});
这是无法正常工作(它将所有 div 的高度设置为等于 rss feed 加载之前最高的 div 的高度),很可能是因为我需要使用实时事件处理程序?有人知道在所有内容完全加载后如何将高度设置为相等吗?
I am developing a site that parses RSS feeds and displays them in a series of divs. After all of the feeds load, I would like to run a jquery function that basically takes the height of the tallest div and sets all of the divs equal to that height. You can view the site here: http://vitaminjdesign.com/adrian/
Currently, I using the jquery equal heights plugin outlined below:
function equalHeight(group) {
var tallest = 0;
group.each(function() {
var thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
and you can call it with:
$(document).ready(function() {
$(".block").equalHeights();
});
This isn't working properly (it sets the height of all the divs equal to the height of the tallest div BEFORE the rss feed loads), most likely due to the fact that I need to use a live event handler? Anyone know how I can set the heights to be equal after everything is completely done loading?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 AJAX 完成时,您需要调用
equalHeight
。您有两种选择:(a) 在每个项目加载后进行调用,或 (b) 在所有项目加载后进行一次调用。equalHeight
看起来并不占用大量资源,因此您不妨每次都进行调用。因此,只需将
equalHeight($(".block"));
添加到每个 AJAX 调用的success
回调中即可。或者,稍微更密集,但在代码方面更简单,是使用
ajaxSuccess
在每次 AJAX 调用后运行一个函数:You need to call
equalHeight
when the AJAX is complete. You have two options: (a) to do the call after each item is loaded or (b) to do the call once after all the items are loaded.equalHeight
doesn't look resource-heavy, so you may as well do the call each time.So just add
equalHeight($(".block"));
to thesuccess
callback of each AJAX call.Alternatively, and slightly more intensive, but simpler in terms of code, is to use
ajaxSuccess
to run a function after every AJAX call: