Skip to content

Instantly share code, notes, and snippets.

@montrealist
Created January 5, 2016 21:31
Show Gist options
  • Save montrealist/b7818cdeb70fb033bd66 to your computer and use it in GitHub Desktop.
Save montrealist/b7818cdeb70fb033bd66 to your computer and use it in GitHub Desktop.
custom.js
console.log('custom shit: '); //TODO
var $list = $( '.products' ),
$items = $list.find( '.product' ),
setHeights = function()
{
$items.css( 'height', 'auto' );
var perRow = Math.floor( $list.width() / $items.width() );
if( perRow == null || perRow < 2 ) return true;
for( var i = 0, j = $items.length; i < j; i += perRow )
{
var maxHeight = 0,
$row = $items.slice( i, i + perRow );
$row.each( function()
{
var itemHeight = parseInt( $( this ).outerHeight() );
if ( itemHeight > maxHeight ) maxHeight = itemHeight;
});
$row.css( 'height', maxHeight );
}
};
setHeights();
$( window ).on( 'resize', setHeights );
$list.find( 'img' ).on( 'load', setHeights );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment