javascript jQuery 砌体问题,显示和加载高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6169520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery masonry issue with display and height on load
提问by nkcmr
I have a masonry container inside of a div that has display:none
in inline style. Because I have a few divs, when the page loads it switches like a slideshow when their button is clicked. This interferes with masonry's ability to gauge the height on load so consequently the bricks spill out of the container.
我在具有display:none
内联样式的 div 中有一个砖石容器。因为我有几个 div,所以当页面加载时,当点击他们的按钮时,它会像幻灯片一样切换。这会干扰砌体测量负载高度的能力,因此砖块会从容器中溢出。
回答by thirtydot
Update:the .load()
part of my answer is not how this should be done.
更新:.load()
我的答案的一部分不是应该如何完成。
See:http://masonry.desandro.com/layout.html#imagesloaded
请参阅:http : //masonry.desandro.com/layout.html#imagesloaded
You can fix it by:
您可以通过以下方式修复它:
- Adding
overflow: hidden
to.panel
to clear the floated elementsinside. Running Masonry on.load()
instead of.ready()
:<script type="text/javascript"> $(document).load(function (){ $('#contain').masonry({ itemSelector: '.item', columnWidth: 100 }); }); </script>
- 添加
overflow: hidden
到.panel
以清除浮动元素里面。 <script type="text/javascript"> $(document).load(function (){ $('#contain').masonry({ itemSelector: '.item', columnWidth: 100 }); }); </script>
Version with those fixes: http://jsbin.com/oyido4/4
带有这些修复的版本:http: //jsbin.com/oyido4/4