Last active
October 3, 2018 19:13
-
-
Save Swivelgames/a3b39d812c6c9e05f92a2562f0b088df to your computer and use it in GitHub Desktop.
Dance elements on a webpage
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
const randBetween = (min, max) => Math.floor(Math.random() * max) + min; | |
const dance = () => { | |
const all = document.body.querySelectorAll('*'); | |
return Array.prototype | |
.slice.apply(all) | |
.reduce( | |
(promise, e) => promise.then( | |
new Promise((resolve, reject) => setTimeout(() => { | |
const top = randBetween(0, window.visualViewport.height); | |
const left = randBetween(0, window.visualViewport.width); | |
e.style.position = 'fixed'; | |
e.style.top = top + 'px'; | |
e.style.left = left + 'px'; | |
e.style.backgroundColor = 'transparent'; | |
e.style.overflow = 'visible'; | |
resolve(); | |
}, 10)) | |
), Promise.resolve() | |
).then(() => | |
new Promise((resolve, reject) => { | |
setTimeout(() => dance(), all * 15) | |
}) | |
); | |
}; | |
dance(); | |
Array.prototype.slice.apply( | |
document.querySelectorAll('a, button') | |
).forEach( | |
(e) => e.addEventListener('click', | |
(e) => e.preventDefault() | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment