javascript - Picture Shuffle -


i have bootstrap , have thumbnails set display set of pictures. want thumbnails stay put , not move. want pictures change inside thumbnails , have size of image adjust thumbnail in.

i want thumbnails stay in 1 spot , maintain size.

i want pictures shuffle in between different thumbnails , adjust it's size match thumbnail in.

i have script shuffles thumbnails around page: (what don't want)

(function($){      $.fn.shuffle = function() {          var allelems = this.get(),             getrandom = function(max) {                 return math.floor(math.random() * max);             },             shuffled = $.map(allelems, function(){                 var random = getrandom(allelems.length),                     randel = $(allelems[random]).clone(true)[0];                 allelems.splice(random, 1);                 return randel;            });          this.each(function(i){             $(this).replacewith($(shuffled[i]));         });          return $(shuffled);      };  })(jquery);  $(function(){ $('ul#list li').shuffle(); }) 

the thumbnails markup looks following.

<ul class="thumbnails" id="list">     <li class="span4">       <a href="#" class="thumbnail">         <img src="http://placehold.it/360x270" alt="">       </a>     </li>     <li class="span3">       <a href="#" class="thumbnail">         <img src="http://placehold.it/260x120" alt="">       </a>     </li>     <li class="span2">       <a href="#" class="thumbnail">         <img src="http://placehold.it/160x120" alt="">       </a>     </li>     <li class="span3">       <a href="#" class="thumbnail">         <img src="http://placehold.it/260x120" alt="">       </a>     </li>     <li class="span2">       <a href="#" class="thumbnail">         <img src="http://placehold.it/160x120" alt="">       </a>     </li>     <li class="span3">       <a href="#" class="thumbnail">         <img src="http://placehold.it/260x120" alt="">       </a>     </li>     <li class="span2">       <a href="#" class="thumbnail">         <img src="http://placehold.it/160x120" alt="">       </a>     </li>     <li class="span3">       <a href="#" class="thumbnail">         <img src="http://placehold.it/260x120" alt="">       </a>     </li>     <li class="span2">       <a href="#" class="thumbnail">         <img src="http://placehold.it/160x120" alt="">       </a>     </li>     <li class="span3">       <a href="#" class="thumbnail">         <img src="http://placehold.it/260x120" alt="">       </a>     </li>     <li class="span2">       <a href="#" class="thumbnail">         <img src="http://placehold.it/160x120" alt="">       </a>     </li>     <li class="span2">       <a href="#" class="thumbnail">         <img src="http://placehold.it/160x120" alt="">       </a>     </li> </ul> 

what change on script shuffles thumbnails make shuffle images , make images adjust thumbnail located in? have tried this. hope making question clear enough on wanting.

give height , width properties img elements like

<img src="http://placehold.it/360x270" alt="" width="360" height="270"/> 

then

(function($){      //+ jonas raoni soares silva     //@ http://jsfromhell.com/array/shuffle [v1.0]     function shuffle(o){ //v1.0         for(var j, x, = o.length; i; j = parseint(math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);         return o;     };      $.fn.shuffle = function() {          var srcs =  this.find('img').map(function(i, el){             return el.src;         });         shuffle(srcs)          return this.each(function(i){             $(this).find('img').attr('src', srcs[i]);         });     };  })(jquery);  $(function(){     $('ul#list li').shuffle(); }) 

demo: fiddle


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -