javascript - jQuery Isotope is not aligning large width item in fitColumns layout mode -
im using jquery isotope
i have 1 item width greater other div. items align items not aligning under large width element.
http://jsfiddle.net/s5vag/1381/
<div id="container"> <div class="item">1</div> <div class="item large">2</div> <div class="item">3</div> <div class="item">4</div> <div class="item">5</div> <div class="item">6</div> <div class="item">7</div> </div> $(function(){ var $container = $('#container'), $items = $('.item'); $container.isotope({ itemselector: '.item', layoutmode : 'fitcolumns', resizescontainer : true, getsortdata : { fitorder : function( $item ) { var order, index = $item.index(); if ( $item.hasclass('large') && index % 2 ) { order = index + 1.5; } else { order = index; } return order; } }, sortby : 'fitorder' }); $items.click(function(){ var $this = $(this); // nothing change if has large class if ( $this.hasclass('large') ) { return; } var $previouslargeitem = $items.filter('.large'); $previouslargeitem.removeclass('large'); $this.addclass('large'); $container // update sort data on changed items .isotope('updatesortdata', $this ) .isotope('updatesortdata', $previouslargeitem ) // trigger layout , sort .isotope(); }); }); can please explain why happening or please provide me better solution.
basically reason behaving way is, is fitcolumns option does; items arranged in vertical columns 1 above other regardless of size of items being arranged.
to better view of available layout options , how items of different sizes check out working example.
it sounds may want try layoutmode: 'masonryhorizontal'.
working example using masonryhorizontal
$(function(){ var $container = $('#container'), $items = $('.item'); $container.isotope({ itemselector: '.item', layoutmode : 'masonryhorizontal', // important bit resizescontainer : true, getsortdata : { fitorder : function( $item ) { var order, index = $item.index(); if ( $item.hasclass('large') && index % 2 ) { order = index + 1.5; } else { order = index; } return order; } }, sortby : 'fitorder' }); $items.click(function(){ var $this = $(this); // nothing change if has large class if ( $this.hasclass('large') ) { return; } var $previouslargeitem = $items.filter('.large'); $previouslargeitem.removeclass('large'); $this.addclass('large'); $container // update sort data on changed items .isotope('updatesortdata', $this ) .isotope('updatesortdata', $previouslargeitem ) // trigger layout , sort .isotope(); }); }); note in example changed width of .items.large even.
Comments
Post a Comment