0

我正在将 Masonry 用于项目并相应地应用 imagesLoaded。

经过多次测试后,我发现这两者几乎完美地结合在一起,但有时它们会失败。99% 的情况是 imagesLoaded 的错。

但是,在 Internet Explorer 上,imageLoaded 似乎比在任何其他浏览器中加载失败的次数要多得多。

这是我发现的:

  • 如果您打开一个新选项卡并直接输入 URL -> imagesLoaded 作品
  • 如果你点击刷新 - > imagesLoaded 作品
  • 如果您输入 URL,点击刷新,在地址栏中标记文本并按 Enter -> imagesLoaded 失败
  • 如果在控制台打开的情况下重复上述操作 -> imagesLoaded 有效
  • 有时如果感觉像它,它就不起作用......

这是怎么回事?这只发生在 Internet Explorer(11、10、9 等)中。

这是JS:

function masonryOptions(){
    $('.post-wrapper').width((((($('#content').width() - ((columnCount*gutter) - gutter)) / columnCount) / $('#content').width()) * 100)+'%');
    $(window).resize(function() {
        $('.post-wrapper').width((((($('#content').width() - ((columnCount*gutter) - gutter)) / columnCount) / $('#content').width()) * 100)+'%');
    });
    container.imagesLoaded(function(){
        $('iframe').load(function() {
            container.masonry({
                itemSelector: '.post-wrapper',
                gutter: gutter,
                transitionDuration: 0
            });
        });
    });
}
$(document).ready(function(){
    masonryOptions();
});

还有一个演示页面: http: //lorem-blogsum.tumblr.com/

4

1 回答 1

0

I have a similary trouble with gutter and margin-bottom;

I don't knwo what problems is exactly, but in my case my problem is padding. I tried to make 2-columns item with masonry.

.item {
   padding: 10px 10px 10px 10px;
   margin-bottom: 10px;
   width: 48%;
}

.gutter {
   width: 4%;
 }

 <div id="id_list">
     <div class="item">
         ...
     </div>
     <div class="item">
         ...
     </div>
 </div>

 $("#id_list").masonry({
     gutter: ".gutter",
     itemSelector: "div.item"
 });

It was buggy in IE. So, I changed my code.

.item {
    margin-bottom: 10px;
    width: 48%;
}

.gutter {
    width: 4%;
}

<div id="id_list">
    <div style="padding: 10px 10px 10px 10px">
        <div class="item">
            ...
         </div>
         <div class="item">
            ...
         </div>
    </div>
</div>

$("#id_list").masonry({
    gutter: ".gutter",
    itemSelector: "div.item"
});

And bug is disappeared! I hope it is helpful for you and I'm sorry for my poor english.

于 2014-08-18T19:17:06.487 回答