Last active
April 24, 2020 20:28
-
-
Save 40thieves/3c14dc3254ec3474580b7dae242442c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let viewport = document.body.getBoundingClientRect() | |
let maxWidth = viewport.width | |
let maxHeight = viewport.height | |
let outer = document.createElement('div') | |
outer.style = "position: absolute; top: 0; left: 0; right: 0;" | |
for (let i = 0; i <= 40; i++) { | |
outer.append(makeImg()) | |
} | |
document.body.append(outer) | |
function makeImg() { | |
let el = document.createElement('img') | |
el.src = 'https://www.peppapig.com/wp-content/uploads/sites/3/2019/02/peppa_pig_splat.png' | |
let width = getRandomInt(100, 300) | |
let left = getRandomInt(0, maxWidth) | |
let top = getRandomInt(0, maxHeight) | |
el.style = `position: absolute; width: ${width}px; left: ${left}px; top: ${top}px;` | |
return el | |
} | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment