我在我的网站中使用jQuery Masonry来显示博客帖子。而且每个帖子块中都添加了Facebook评论框。当有新的注释时,容器div会扩展,不幸的是会与下面的重叠。在这种情况下,我需要重新运行Masonry脚本来重新加载这些块。
因此,我使用Ben Alman's Jquery Resize Event Plugin来检查div高度的变化,以便砖石脚本根据它们的新大小重新定位块,并避免重叠。
虽然它不工作,而且当我用firebug检查它时,似乎没有错误。我完全是Jquery的新手,我希望我在这里只是犯了一个简单的错误。
如果你想看一下,请查看bjk-tribun.com,当你在评论框中输入一些评论时,你会看到重叠的部分。
$(function(){
// Bind the resize event. When any test element's size changes, update its
// corresponding info div.
var iframe = $(".fb_iframe_widget");
// Called once the Iframe's content is loaded.
iframe.load(function(){
// The Iframe's child page BODY element.
var iframe_content = iframe.contents().find('body');
// Bind the resize event. When the iframe's size changes, update its height as
// well as the corresponding info div.
iframe_content.resize(function(){
var elem = $(this);
// Resize the IFrame.
iframe.css({ height: elem.outerHeight( true ) });
$('#sort').masonry(reloadItems);
// Resize the Iframe and update the info div immediately.
iframe_content.resize();
});
});
发布于 2012-01-30 17:09:07
根据您使用的jQuery版本,您可能需要在css属性中添加px单位:
iframe.css({ height: elem.outerHeight( true ) + "px" });
发布于 2012-01-30 20:18:24
好吧,我不知道为什么,但一旦我关闭了colorbox.js,这是一个灯箱插件,Jquery砖石插件开始对div调整大小做出反应。因此,如果任何人遇到同样的问题,他们应该首先尝试禁用其他jquery插件,这样就不会花整个星期的时间在这个问题上。
我还禁用了我在上面插入的Ben Alman插件。Masonry足以处理resize事件。
https://stackoverflow.com/questions/9058400
复制相似问题