Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.