javascript - randomly move images in a fixed area -


i using code move images randomly in area. need show atleast 3 images always. here had done:

html

<div class="fade">image 1</div> <div class="fade">image 2</div> <div class="fade">image 3</div> <div class="fade">image 4</div> <div class="fade">image 5</div> <div class="fade">image 6</div> 

jquery

(function fadeindiv() {     var divs = jquery('.fade');     var elem = divs.eq(math.floor(math.random() * divs.length));     if (!elem.is(':visible')) {         elem.prev().remove();         elem.fadein(math.floor(math.random() * 1000), fadeindiv);     } else {          elem.fadeout(math.floor(math.random() * 1000), function() {             elem.before('<div>&nbsp;</div>');             fadeindiv();         });     } })(); 

this code fadein , fadeout images randomly result show 2 images @ time 1 image @ time sometime 3. need show 3 images in 6 images every time fadein fadeout functionality.

here how home page like:

image1          image2          image3 

i want like:

       image1  image2        image3 

or

       image1         image2  image3 

or other pattern images

try recursive algorithm delay lengths depending on random order of objects:

window.refresh = function(delay) {    delay *= 1000;    var doms = [];    var randos = [];    var index = 0;      function fadeout() {      if (index < 3) {        var random = $(doms.get(randos[index]));        $(random).delay(delay + 200 * index).fadeto(200, 0, function() {          $(random).css("visibility", "hidden");        });        doms = doms.not(random);        index++;        fadeout(doms);      }    }      doms = $('.grid-item');    doms.css("visibility","visible");    doms.css("opacity","1");    var num = math.floor(math.random() * doms.length);    (var = 0; < doms.length; i++) {      while (randos.indexof(num) > -1) {        num = math.floor(math.random() * doms.length);      }      randos.push(num);    }    fadeout();  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="grid">    <div class="grid-item">image 1</div>    <div class="grid-item">image 2</div>    <div class="grid-item">image 3</div>    <div class="grid-item">image 4</div>    <div class="grid-item">image 5</div>    <div class="grid-item">image 6</div>  </div>  <br>  <button onclick="refresh(0)">trigger animation</button>  <br>  <br>  <input type="number" placeholder="time in seconds">  <button onclick="refresh($(this).prev().val())">trigger delayed animation</button>


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -