砌体当前不显示物品

时间:2014-07-19 16:56:47

标签: masonry

我正在使用砌体jquery插件在容器中排列一些图像,插件似乎正在工作,但它没有正确显示项目。有些空间可以用物品填充,但是物品在下一行留下“漂浮”,这不应该发生。

这个问题可以在这里看到: http://riley87.co.uk/theme/ionic/portfolio-masonry.html

以下是代码:

<ul class="col full-width masonry-wrap filter-wrap">
    <li class="item web" style="width: 49.9099099099%;">                    
        <a href="img/portfolio/554x520-1.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/554x520-1.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 49.9099099099%;">                    
        <a href="img/portfolio/554x259-1.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/554x259-1.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 24.8648648649%;">                    
        <a href="img/portfolio/276x259-1.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/276x259-1.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 24.8648648649%;">                    
        <a href="img/portfolio/276x520-1.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/276x520-1.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 24.8648648649%;">                    
        <a href="img/portfolio/276x259-2.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/276x259-2.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 49.9099099099%;">                    
        <a href="img/portfolio/554x259-2.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/554x259-2.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 49.9099099099%;">                    
        <a href="img/portfolio/554x259-3.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/554x259-3.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 49.9099099099%;">                    
        <a href="img/portfolio/554x520-2.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/554x520-2.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 24.8648648649%;">                    
        <a href="img/portfolio/276x520-2.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/276x520-2.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 24.8648648649%;">                    
        <a href="img/portfolio/276x259-3.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/276x259-3.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 49.9099099099%;">                    
        <a href="img/portfolio/554x259-4.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/554x259-4.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>

    <li class="item web" style="width: 24.8648648649%;">                    
        <a href="img/portfolio/276x259-4.jpg"  class="img-wrap view" rel="photography">
            <img src="img/portfolio/276x259-4.jpg" alt="">
            <div class="img-overlay">
                <div class="icon-only"><i class="fa fa-eye"></i></div>
            </div>
        </a>
    </li>
</ul>

<script>
    $(document).ready(function(){
        var container = document.querySelector('.masonry-wrap');
        var msnry = new Masonry( container, {
          // options
          itemSelector: '.item'
        });
        var msnry;
        // initialize Masonry after all images have loaded
        imagesLoaded( container, function() {
          msnry = new Masonry( container );
        });
    });
</script>

1 个答案:

答案 0 :(得分:0)

首先,您需要删除msnry冗余声明,并保留在加载图像后被触发的声明。

其次,在设置砌体对象时,尝试将.item选择器定义为columnWidth选项:

$(document).ready(function(){
  var $container = $('.masonry-wrap');
  // initialize Masonry after all images have loaded
  $container.imagesLoaded(function() {
    $container.masonry({
      itemSelector: '.item',
      columnWidth: '.item'
    });
  });
});