Created
October 11, 2015 21:49
-
-
Save michalbe/0cb0d1005b94543ae653 to your computer and use it in GitHub Desktop.
random shows wallpaper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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