TheodoreV
TheodoreV

Reputation: 304

Multiple instances of isotope jQuery

I have a really weird problem

I am loading two separate divs as show below, the span element is in order to store how many items per row exist in each Isotope's instance

<div class='instagram' id='insta12'>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
<span id="hiddenValue" >5</span>
</div>

<div class='instagram' id='insta101'>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
<div class="item">...</div>
<span id="hiddenValue">3</span>
</div>

And my js file is as shown below

jQuery(document).ready(function($) {
  var tmpNum="";
  var numberOfImages=3;
  var $container = $('.instagram');
  $container.each(function ()  {

  tmpNum=  $(this).find('span#hiddenValue').text();
  numberOfImages=parseInt(tmpNum);
  var tmpid=$(this).attr("id");
  alert(tmpid);
    $("#"+tmpid).imagesLoaded(function() {
      $("#"+tmpid).isotope({ 
        resizable: false, 
        // disable normal resizing
        // set columnWidth to a percentage of container width
        masonry: { 
        columnWidth:  $("#"+tmpid).width() / numberOfImages 
        } 
      });

    }); //isotope
  });         //each
}); //dom ready

Although it seems that the script is working, the second container has as much items per row as the first container. Any ideas?

Upvotes: 1

Views: 1649

Answers (1)

TheodoreV
TheodoreV

Reputation: 304

Solved

jQuery(document).ready(function($) {
    var tmpNum = "";
    var $container = $('.instagram');
    $container.each(function() {
        var tmpid = $(this).attr("id");
        tmpNum = $("#" + tmpid + " span#hiddenValue").text();
        var numberOfImages = parseInt(tmpNum, 10);
        $(this).imagesLoaded(function() {
            $(this).isotope({
                resizable: false,
                // disable normal resizing
                // set columnWidth to a percentage of container width
                masonry: {
                    columnWidth: $(this).width() / numberOfImages
                }
            });
        }); //isotope
    }); //each
}); //dom ready

Upvotes: 1

Related Questions