Skip to content

Instantly share code, notes, and snippets.

@40thieves
Last active April 24, 2020 20:28
Show Gist options
  • Save 40thieves/3c14dc3254ec3474580b7dae242442c6 to your computer and use it in GitHub Desktop.
Save 40thieves/3c14dc3254ec3474580b7dae242442c6 to your computer and use it in GitHub Desktop.
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