Skip to content

Instantly share code, notes, and snippets.

@dmouse
Last active December 10, 2015 23:59
Show Gist options
  • Save dmouse/4513422 to your computer and use it in GitHub Desktop.
Save dmouse/4513422 to your computer and use it in GitHub Desktop.
(function($){
$.randomages = {
defaults: {
path: 'images/',
images: ['image1.jpg','image2.jpg']
}
}
$.fn.extend({
randomages:function(config) {
var config = $.extend({}, $.randomages.defaults, config);
return this.each(function() {
var i_n = config.images;
var ln = Math.floor(Math.random()*i_n.length);
var image = i_n[ln];
var fullPath = config.path + image;
$(this).css({
'background' : 'url(' + fullPath + ') no-repeat'
});
});
}
});
})(jQuery);
$('#zone').randomages({
path: 'mi_path/images',
images: ['img_1.jpg', 'img_2.jpg','img_3.jpg']
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment