javascript - Issue with Isotope js filter -


i'm having problem applying filter in isotope js. of content seems disappear when applying filters. (note: question using isotope in plain vanilla js environment , not jquery).

i have series of divs

<div id="thecontainer">  <div class="displaybox catnum1"> div content </div>  <div class="displaybox catnum1"> div content </div>  <div class="displaybox catnum2"> div content </div>  <div class="displaybox catnum2"> div content </div>  <div class="displaybox catnum3"> div content </div> </div> 

so have simple function filter category:

function showcat(catnumber) {     var container = document.getelementbyid('thecontainer');             var iso = new isotope(container);     iso.arrange(         filter: '.catnum'+catnumber,         });  } 

if call showcat(2), seems work fine. 2 div's 'catnum2' class visible. others disappear. far good...

but if call showcat again (eg: showcat(1); ) instead of re-filtering show 'catnum1' div's, of div's disappear, , have blank screen.

i have tried pre-filtering "*" filter type. have tried doing sortby "original-order", prior executing function again new filter request. nothing seems restore div's original view. function seems run once, , successive calls seem add new filters onto first filter request, rather preforming new filter request scratch.

is there need prior running new filter? clues why disappearing?

problem solved.

if else has similar issue using isotope without jquery, hope following function proves useful. no frameworks (other isotope) necessary.

(this hide , reveal div's defined in question).

call function with: cats.showcat(1);

reset original (nonfiltered view) null argument: cats.showcat();

var cats = (function(){  function cats(element) {     this.element = element;      this.iso = null;      this.currentcat = null;       this.init();  };  cats.prototype.init = function() {     this.iso = new isotope(this.element); };  cats.prototype.showcat = function(catnumber) {     if(this.currentcat == catnumber){         return;     };      this.currentcat = catnumber;      if(catnumber == null){         this.iso.arrange({             filter: '*'         });     }else{         this.iso.arrange({             filter: '.catnum' + catnumber         });     };  };    return cats;  })();   var cats = new cats(document.getelementbyid('thecontainer')); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -