javascript - Change one random image in a list -


i create client's logo wall : https://www.squarespace.com/ scroll down until "trusted world’s best" section.

to create same effect, begin generate list of 8 elements , after put random src image array inside list : https://jsfiddle.net/xroad/avn64tw0/6/

after that, tried change randomly 1 image after other : https://jsfiddle.net/xroad/avn64tw0/8/

i don't know how change 1 random image ? , after add little move effect bottom top.

html

<div class="list-items"></div> 

css

.list-items {     max-width: 500px; }  .item {     display: inline-block;     float: left;     margin: 10px;     height: 100px;     width: 100px;     line-height: 100px;     background-repeat: no-repeat;     background-size: cover;      img {         display: inline-block;         width: 100%;         height: auto;         max-height: 100%;         vertical-align: middle;     } } 

jquery

// list of images // var logos = ["http://wallpaper-gallery.net/images/image/image-1.jpg", "http://wallpaper-gallery.net/images/image/image-2.jpg", "http://wallpaper-gallery.net/images/image/image-3.jpg", "http://wallpaper-gallery.net/images/image/image-4.jpg", "http://wallpaper-gallery.net/images/image/image-5.jpg", "http://wallpaper-gallery.net/images/image/image-6.jpg", "http://wallpaper-gallery.net/images/image/image-7.jpg", "http://wallpaper-gallery.net/images/image/image-8.jpg"];  // generate 8 items // var i; (i = 0; < 8; ++i) {     $(".list-items").append('<a href="" class="item"><img src="" alt=""></a>'); }  // shuffle function // function shuffle(o) {     (var j, x, = o.length; i; j = math.floor(math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);     return o; };  logos = shuffle(logos);  // push src in image tags // $('.item img').each(function(i) {     $(this).attr('src', logos[i]); });  // change 1 image after other // count = 0;   setinterval(function () {     count++;     $(".item img").fadeout(600, function () {       $(this).attr('src', logos[count % logos.length]).fadein(600);     });  }, 5000); 

the "change image" part don't work like, change image while 1 image after other.

update

with of @chrisg got image change randomly, got duplicate image.

https://jsfiddle.net/xroad/avn64tw0/11/


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -