Created
November 7, 2012 10:54
-
-
Save FutureMedia/4030850 to your computer and use it in GitHub Desktop.
Masonry responsive layout technique -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// As used by Codroprs | |
// http://tympanus.net/codrops/collective/collective-36/ | |
jQuery(document).ready(function($) { | |
var CollManag = (function() { | |
var $ctCollContainer = $('#ct-coll-container'), | |
collCnt = 1, | |
init = function() { | |
changeColCnt(); | |
initEvents(); | |
initPlugins(); | |
}, | |
changeColCnt = function() { | |
var w_w = $(window).width(); | |
if( w_w <= 600 ) n = 1; | |
else if( w_w <= 768 ) n = 2; | |
else n = 3; | |
}, | |
initEvents = function() { | |
$(window).on( 'smartresize.CollManag', function( event ) { | |
changeColCnt(); | |
}); | |
}, | |
initPlugins = function() { | |
$ctCollContainer.imagesLoaded( function(){ | |
$ctCollContainer.masonry({ | |
itemSelector : '.ct-coll-item', | |
columnWidth : function( containerWidth ) { | |
return containerWidth / n; | |
}, | |
isAnimated : true, | |
animationOptions: { | |
duration: 400 | |
} | |
}); | |
}); | |
$ctCollContainer.colladjust(); | |
$ctCollContainer.find('div.ct-coll-item-multi').collslider(); | |
}; | |
return { init: init }; | |
})(); | |
CollManag.init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Basic idea seems to be to add a columnselector which finds out how many columns can be set. Second step is to use the smartresize event in the function. Third step is to call masonry with the "dynamic" width of columns.