2015-10-30 112 views
1

我有一个完全流体的包装布局的砌体网格设置。但是,在调整浏览器大小时,网格会自行重新排列。我想保持网格完全静态。防止砌体网格重新排列

的jsfiddle:http://jsfiddle.net/5gL8bz3e/1/

这里是我的CSS:

body { 
    overflow-y: scroll; 
    } 

.grid-item, 
.grid-sizer { 
    width: 5.3125vw; 
    } 

.gutter-sizer { 
    width: 1vw; 
    } 

.grid-item { 
    float: left; 
    height: auto; 
    background: #fff; 
    border: 0px solid #fff; 
    margin-bottom: 0vw; 
    background: none; 
    } 

.grid-item img { 
    width: 100%; 
    height: auto; 
    margin: 0; 
    padding: 0; 
    display: block; 
    } 

.grid-item--width2, .grid-item--width2b { width: 11.625vw; } 
.grid-item--width4 { width: 24.25vw; } 
.grid-item--width6 { width: 36.875vw; } 

.grid { 
    background: lightyellow; 
    width: 75vw; 
    position: relative; 
    left: 12.625vw; 
    top: 12.625vw; 
    margin-top: 0; 
    min-height: 1000px; 
    } 

.stamp { 
    width: 11.625%; 
    height: 100%; 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    background: lightpink; 
} 

.stamp1 { 
    left: 0; 
    } 

.stamp2 { 
    right: 0; 
    } 

HTML:

<div class="grid"> 
    <div class="gutter-sizer"></div> 
    <div class="grid-sizer"></div> 

    <div class="grid-item grid-item--width6"> 
     <img src="http://placehold.it/1180x760"/> 
    </div> 

    <div class="grid-item grid-item--width4"> 
     <img src="http://placehold.it/776x496"/> 
    </div> 

    <div class="grid-item grid-item--width2b"> 
     <img src="http://placehold.it/372x496"/> 
    </div> 

    <div class="grid-item grid-item--width2"> 
     <img src="http://placehold.it/372x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

     <div class="grid-item grid-item--width6"> 
     <img src="http://placehold.it/1180x760"/> 
    </div> 

    <div class="grid-item grid-item--width4"> 
     <img src="http://placehold.it/776x496"/> 
    </div> 

    <div class="grid-item grid-item--width2b"> 
     <img src="http://placehold.it/372x496"/> 
    </div> 

    <div class="grid-item grid-item--width2"> 
     <img src="http://placehold.it/372x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

     <div class="grid-item grid-item--width6"> 
     <img src="http://placehold.it/1180x760"/> 
    </div> 

    <div class="grid-item grid-item--width4"> 
     <img src="http://placehold.it/776x496"/> 
    </div> 

    <div class="grid-item grid-item--width2b"> 
     <img src="http://placehold.it/372x496"/> 
    </div> 

    <div class="grid-item grid-item--width2"> 
     <img src="http://placehold.it/372x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

     <div class="grid-item grid-item--width6"> 
     <img src="http://placehold.it/1180x760"/> 
    </div> 

    <div class="grid-item grid-item--width4"> 
     <img src="http://placehold.it/776x496"/> 
    </div> 

    <div class="grid-item grid-item--width2b"> 
     <img src="http://placehold.it/372x496"/> 
    </div> 

    <div class="grid-item grid-item--width2"> 
     <img src="http://placehold.it/372x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

    <div class="grid-item grid-item--width1"> 
     <img src="http://placehold.it/170x232"/> 
    </div> 

</div> 
+0

这就是同位素砌体和打包布局设计要做的,重新排列网格以填补空白。请考虑fitRows。 – Macsupport

回答

0

我认为选择isResizeBound将做到这一点。默认为true,但您可以指定。

var msnry = new Masonry('.grid', { 
    columnWidth: 200, 
    itemSelector: '.grid-item', 
    isResizeBound: false 
}); 

有关详细信息,请参阅doc

+0

我不知道这是否正常工作 - 当我将它添加到JSFiddle并调整它的大小时,它会打破线条。我还应该提到它似乎根据屏幕大小随机生成一个布局。我希望能够配置一个布局而不是永远不会改变。 –