Skip to content

Instantly share code, notes, and snippets.

@ederduran
Last active August 29, 2015 14:06
Show Gist options
  • Save ederduran/8949e5978f05fca08d59 to your computer and use it in GitHub Desktop.
Save ederduran/8949e5978f05fca08d59 to your computer and use it in GitHub Desktop.
Pequeño plugin jQuery para backgrounds aleatorios - con jQuery 1.11.0
(function(e){$.fn.extend({backgroundRdm:function(e){this.each(function(){backgroundsTotal=e.length;random=Math.floor(Math.random()*backgroundsTotal+0);finalBack=e[random];$(this).css("background-image","url("+finalBack+")")})}})})(jQuery)
$(document).ready(function(){
//Asignamos a body un background aleatorio tomando en cuenta la lista de backgrounds que le pasamos a traves de un array
$("body").backgroundRdm([
'http://ederduran.com/wp-content/uploads/2014/09/square_bg.png',
'http://ederduran.com/wp-content/uploads/2014/09/pat-17.png',
'http://ederduran.com/wp-content/uploads/2014/09/gplaypattern.png',
'http://ederduran.com/wp-content/uploads/2014/09/light_wool.png',
'http://ederduran.com/wp-content/uploads/2014/09/grey.png',
'http://ederduran.com/wp-content/uploads/2014/09/ecailles.png',
'http://ederduran.com/wp-content/uploads/2014/09/cream_pixels.png',
'http://ederduran.com/wp-content/uploads/2014/09/crossword.png',
'http://ederduran.com/wp-content/uploads/2014/09/transp_bg.png',
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment