2015-10-30 113 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並調整它的大小時,它會打破線條。我還應該提到它似乎根據屏幕大小隨機生成一個佈局。我希望能夠配置一個佈局而不是永遠不會改變。 –