Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 28th, 2012  |  syntax: None  |  size: 1.06 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Fix my random image positioning script so the images don't overlap
  2. var images = [];
  3.  
  4. function init() {
  5.     $('.friend-selection li > div').each(function(){
  6.         var id = this.id;
  7.         var img = $('#img_' + id);
  8.         var randomTop = 500*Math.random(); //random top position
  9.         var randomLeft = 500*Math.random(); //random left position
  10.  
  11.         $("#parent_" + id).css({ //apply the position to parent divs
  12.             top : randomTop,
  13.             left : randomLeft
  14.         });
  15.     });
  16. };
  17.  
  18. init();
  19.        
  20. <li id="parent_picture1">
  21.     <div id="picture1">    
  22.         <div class="glow"></div>
  23.         <img src="static/img/voorbeeld/vrouw.jpg" width="111" height="166" id="img_picture1">
  24.         <span class="name">Naam Achternaam</span>
  25.     </div>      
  26. </li>
  27.        
  28. var slots = [];
  29.  
  30.         for (var y = 0; y < 5; y++)
  31.         {
  32.             for (var x = 0; x < 5; x++)
  33.             {
  34.                 slots.push([x, y]);
  35.             }
  36.         }
  37.  
  38.         slots.sort(function () { return (0.5 - Math.random()); });
  39.  
  40.         $('.friend-selection li > div').each(function() { ... }