javascript - How to write while members of class still exist in page condition -


in jquery or js, preferably jquery or js supported, how can while condition there still members of class on page.

what doing in suite of while systematically removing elements in class, can not remove them @ once.

let's class .card.

here code:

$('#dismissallbutton').click(function(){     while($('.datacard').length>0){         $('.right').eq(0).remove();         $('#left').children('.datacard').first().addclass('animated').addclass('right');         settimeout(function(){             $('.right').eq(0).remove();             $('#right').children('.datacard').first().addclass('animated').addclass('right');         }, 150);     } }); 

html:

<div id="left">     <div class="datacard"></div>     <div class="datacard"></div> </div> <div id="right">     <div class="datacard"></div>     <div class="datacard"></div> </div> 

you don't need while loop. instead, first iterate on each list, within each list, iterate on each card. allows set delay on removing card based on list in can effect of removing 1 1 each list @ same time.

$("#dismissallbutton").on("click", function() {     $("#left, #right").each(function(i){         $(".datacard",this).each(function(ii) {             var card = $(this);             settimeout(function() {                 card.addclass("right");                 settimeout(function() {                     card.remove();                 },500);             }, i*250+ii*500); // adjust `250` , `500` needed.         });     }); }); 

demo

250 delay between left , right, , 500 animation duration (dont forget update css transition reflect that)


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 -