Skip to content

Instantly share code, notes, and snippets.

@michalbe
Created October 11, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalbe/0cb0d1005b94543ae653 to your computer and use it in GitHub Desktop.
Save michalbe/0cb0d1005b94543ae653 to your computer and use it in GitHub Desktop.
random shows wallpaper
var series = document.querySelectorAll('#series .cover');
var x = 6;
var y = 3;
var sizeX = 1200;
var sizeY = 800;
var topPos = 0;
var leftPos = 0;
var totalCovers = x*y;
var result = 0;
while (result < totalCovers) {
var show = series[~~(Math.random()*series.length)];
if (show.style.backgroundImage) {
result++;
var el = document.createElement('div');
el.style.backgroundImage = show.style.backgroundImage;
el.style.width = sizeX/x + 'px';
el.style.height = sizeY/y + 'px';
el.style.backgroundSize = 'cover';
el.style.position = 'absolute';
el.style.top = topPos + 'px';
el.style.left = leftPos + 'px';
document.body.appendChild(el);
if (result%x === 0) {
topPos += sizeY/y;
leftPos = 0;
} else {
leftPos += sizeX/x;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment