jquery - Isotope gutter/spacing on page load, no gutter/spacing on window resize -


on page load, isotope adds gutter between isotope items. when resize window, 1px, fix layout.

i've been racking brain why isotope adding spacing between images. on 1 page, , code identical other pages, exception being i'm loading in larger jpg images page.

i've created codepen code/dependencies you'll see works there. if have tips on improving code, please let me know.

here's isotope function:

/**  * item filter  *  */ itemfilter: function(isocontainer, $isoselector) {     var itemgroup;     var viewbyselect;     var namefilter;     var buttonfilter;     var usednames = {};      var $isocontainer = $(isocontainer);      var $win = $(window);     // lazy load w/ sorting/filtering enabled     var $imgs = $('.lazy');     // init isotope     var $container = $isocontainer.isotope({         itemselector: $isoselector,         layoutmode: 'fitrows',         animationengine: 'best-available',         getsortdata: {             name: '.name'         },         filter: function() {             var $this = $(this);              var itemgroupresult = itemgroup ? $this.is(itemgroup) : true;             var viewbyselectresult = viewbyselect ? $this.is(viewbyselect) : true;             var namefilterresult = namefilter ? $this.is(namefilter) : true;             var buttonresult = buttonfilter ? $this.is(buttonfilter) : true;              return itemgroupresult && viewbyselectresult && namefilterresult && buttonresult;         }     });      // fixes layout issues when images still loading.     $container.imagesloaded().progress(function() {         $container.isotope('layoutitems');     });      // load images when filtering initiated ,      // have new html layout lazyload on.     $container.isotope('on', 'layoutcomplete', function () {         features.loadvisible($imgs, 'lazylazy');     });      // load images on scroll event lazylazy.     $win.on('scroll', function () {         features.loadvisible($imgs, 'lazylazy');     });      // initialize lazyload fadein effect , failure_limit.     // listening on event 'lazylazy'     $imgs.lazyload({         effect: "fadein",         failure_limit: math.max($imgs.length - 1, 0),         event: 'lazylazy'     });      // select filtering - role     $('.view-by-select').on('change', function() {         viewbyselect = $('option:selected', this).data('filter');         $container.isotope();     });      // filtering - profile name     $('.filter-title').on('click', 'span', function() {         namefilter = $(this).hasclass('name');         $container.isotope({ sortby: namefilter });     });      // reset filtering     $('.filter-reset').on('click', function() {         $('.view-by-select').val('default').trigger('change');         buttonfilter = $(this).data('filter');         $container.isotope();     });      // remove duplicate roles select list     var $selectlist = $('select.view-by-select > option');     $selectlist.each(function () {         if(usednames[this.text]) {             $(this).remove();         } else {             usednames[this.text] = this.value;         }     });  } 

here's image of issue i'm experiencing:

image gutters present when shouldn't be

well.. solution dirty @ best:

itemfilter: function(isocontainer, $isoselector) {     var $win = $(window);     $win.load(function() {         var itemgroup;         var viewbyselect;         var namefilter;         var buttonfilter;         var usednames = {};          var $isocontainer = $(isocontainer);           // lazy load w/ sorting/filtering enabled         var $imgs = $('.lazy');          // init isotope         var $container = $isocontainer.isotope({             itemselector: $isoselector,             layoutmode: 'fitrows',             animationengine: 'best-available',             getsortdata: {                 name: '.name'             },             filter: function() {                 var $this = $(this);                  var itemgroupresult = itemgroup ? $this.is(itemgroup) : true;                 var viewbyselectresult = viewbyselect ? $this.is(viewbyselect) : true;                 var namefilterresult = namefilter ? $this.is(namefilter) : true;                 var buttonresult = buttonfilter ? $this.is(buttonfilter) : true;                  return itemgroupresult && viewbyselectresult && namefilterresult && buttonresult;             }         });         $container.isotope('layout');          // fixes layout issues when images still loading.         $container.imagesloaded().progress(function() {             $container.isotope('layoutitems');         });          // load images when filtering initiated ,          // have new html layout lazyload on.         $container.isotope('on', 'layoutcomplete', function () {             features.loadvisible($imgs, 'lazylazy');         });          // load images on scroll event lazylazy.         $win.on('scroll', function () {             features.loadvisible($imgs, 'lazylazy');         });          // initialize lazyload fadein effect , failure_limit.         // listening on event 'lazylazy'         $imgs.lazyload({             effect: "fadein",             failure_limit: math.max($imgs.length - 1, 0),             event: 'lazylazy'         });          // select filtering - role         $('.view-by-select').on('change', function() {             viewbyselect = $('option:selected', this).data('filter');             $container.isotope();         });          // filtering - profile name         $('.filter-title').on('click', 'span', function() {             namefilter = $(this).hasclass('name');             $container.isotope({ sortby: namefilter });         });          // reset filtering         $('.filter-reset').on('click', function() {             $('.view-by-select').val('default').trigger('change');             buttonfilter = $(this).data('filter');             $container.isotope();         });          // remove duplicate roles select list         var $selectlist = $('select.view-by-select > option');         $selectlist.each(function () {             if(usednames[this.text]) {                 $(this).remove();             } else {                 usednames[this.text] = this.value;             }         });      }); } 

i wrapped entire isotope script in $(window).load() function. fixes layout issue on page load. have better solution?


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -