1

我在我的站點中使用jQuery Masonry來顯示博客文章。並且每個帖子塊都添加了Facebook評論框。當有新的評論時,容器div擴展,不幸的是與下面的一個重疊。在這種情況下,我需要重新運行砌體腳本來重新加載塊。 Screenshot如何檢查div的高度來重新排列div塊

所以我使用Ben Alman's Jquery Resize Event Plugin檢查在div的高度變化,這樣的砌體腳本根據新的大小重新定位塊,避免重疊。

雖然它不工作,並且當我用螢火蟲檢查它時似乎沒有錯誤。我是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(); 
    }); 
}); 

回答

0

根據您使用的jQuery的版本,你可能需要在你的CSS屬性添加的PX裝置:

iframe.css({ height: elem.outerHeight(true) + "px" }); 
0

好吧,我不知道爲什麼,但我一旦打開顏色框的。 js這是一個燈箱插件Jquery Masonry插件開始對div的大小作出反應。因此,如果有人遇到同樣的問題,他們應該首先嚐試禁用其他jquery插件,以避免花費整整一週的時間。

我還禁用了本人插入的Ben Alman插件。砌體足以應付調整大小事件。