2012-10-05 30 views
2

絕對把我的頭髮拉出來。在GitHub上似乎沒有提供黑白解決方案 - 這很奇怪,因爲它看起來像一個相當簡單的概念。也許我只是不明白。同位素與媒體查詢

基本上,我想創建一個流體響應組合 - 採用Isotope篩選項目。過濾效果很好,4列完全流暢,當您調整窗口大小時,一切看起來都很棒。

無論其,用於移動設備和平板佈局,我只需從4列佈局適應2列佈局。

我嘗試這樣做:。

$(window).load(function(){ 

    var $container = $('#thumbs'); 
    $container.isotope({ 
     filter: '*', 
     animationOptions: { 
      duration: 750, 
      easing: 'linear', 
      queue: false, 
     }, 
    }); 

    // initialize Isotope 
    $container.isotope({ 
     // options... 
     resizable: false, // disable normal resizing 
     // set columnWidth to a percentage of container width 
     masonry: { columnWidth: $container.width()/4 }, 
    }); 

    // update columnWidth on window resize 
    $(window).smartresize(function(){ 
     $container.isotope({ 
      // update columnWidth to a percentage of container width 
      masonry: { columnWidth: $container.width()/4 } 
     }); 
    }); 

// My attempt at using media queries to change 'columnWidth' 
    $(window).resize(function() { 
     var width = $(window).width(); 
     if (width < 768) { 
      $container.isotope({ 
       // update columnWidth to half of container width 
       masonry: { columnWidth: $container.width()/2 } 
      }); 
     } 
    }); 
}); 

沒有工作:(

任何幫助,將不勝感激

回答

2

這應該設置你的列數然後你只需鴻溝與columns

var columns; 

// set column number 
setColumns(); 

// rerun function when window is resized 
$(window).on('resize', function() { 
    setColumns(); 
}); 

// the function to decide the number of columns 
function setColumns() { 
    if($(window).width() <= 768) { 
    columns = 2; 
    } else { 
    columns = 4; 
    } 
} 
+0

感謝您的支持。傳說。 – Salmonface

+0

我意識到我爲什麼不工作。在'$ container.isotope({''我正在使用'masonry:{columnWidth:$ container.width()/ 4}''而不是'columns:4'的函數。Sorted。Thanks again。 – Salmonface

+0

Hi @Salmonface我有同樣的問題,當窗口縮小時,我似乎無法將佈局更改爲兩列。您是如何解決這個問題的?var $ container = $('#filter_container'); $ container.isotope({itemSelector:' .element」, \t \t可調整大小:假,//禁用正常調整 砌築:{columnWidth時:$ container.width()/ 3} \t \t \t \t }); \t \t //更新columnWidth時上窗口resiz È \t \t $(窗口).smartresize(函數(){ \t \t $ container.isotope({ \t \t \t //更新columnWidth時到容器寬度 \t \t \t砌築的百分比:{columnWidth時:$容器。 width()/ 3} \t \t}); ; \t \t})' – Grundizer