javascript - fadeIn() elements in array, randomly (ie, not in order), at different times -
i have several sentences written, "words" within tags, same class. have managed fill array elements. however, appear @ same time, , in order down paragraph in sequential order (ie, if element 5 first printed, n+1 element greater 5, , on)
also, in loop, if for(var i=0;i < numelements;i++) .....32 number of unique elements. must set numelements way larger 32. ie elements not appear unless numelements >=90. why this?
attempt:
$(document).ready(function() { var spanarray = []; var spanlength, index; /* populate array elements of class .fadein */ $(".fadein").each(function() { spanarray.push(this); }) spanlength = (spanarray.length); for(var = 0; < 33; i++) { index = math.floor(math.random() * (spanarray.length)); $(spanarray[index]).delay(400).fadeto(500,1, function() { $(spanarray).splice(index,1); }); } });
basically: all elements appear @ same time numelements not display elements unless numelements >>> actualnumelements
ex: working jsfiddle
i found answer wondering!
$(document).ready(function() { $("#contact").click(function() { $(".fadein").each(function() { var word = this; settimeout(function() { $(word).css("opacity","1"); }, math.random() * 3000) }); });