Skip to content

Instantly share code, notes, and snippets.

@johnbhartley
Last active August 29, 2015 14:22
Show Gist options
  • Save johnbhartley/8864457749fa9d0face5 to your computer and use it in GitHub Desktop.
Save johnbhartley/8864457749fa9d0face5 to your computer and use it in GitHub Desktop.
Randomly places images inside a gallery in different absolute spot.
PlaceImages: function(galH, galW) {
// galH and galW are specified width/height
// either input in the function or could use width/height of gallery
var gal = $('.hp-gallery-images');
var imgs = $('.hp-gallery img');
imgs.each( function (index, el) {
var randNum_T = Math.round(Math.random() * galH);
var randNum_L = Math.round(Math.random() * galW);
var randClass = Math.round(Math.random() * 5);
var newIMG = $('<img />').attr({src: this.src, alt: 'space'}).addClass('layer-'+randClass).css({'top': randNum_T + 'px', 'left': randNum_L});
gal.append(newIMG);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment