Skip to content

Instantly share code, notes, and snippets.

@alicethewhale
Created December 14, 2018 11:29
Show Gist options
  • Save alicethewhale/98e39f5f3c0a58f287c54f3bb7705c3c to your computer and use it in GitHub Desktop.
Save alicethewhale/98e39f5f3c0a58f287c54f3bb7705c3c to your computer and use it in GitHub Desktop.
const catButton = document.getElementById("cat-button");
function dropDecs() {
\\ Take every other decoration on the tree
Array.from(document.querySelectorAll(".decoration")).filter((dec, index) => index % 2 === 1).forEach(decoration => {
\\ Set the top value of each one to a random number somewhere around the base of the tree
decoration.style.top = `${(Math.random()*30)+610}px`;
\\ Rotate each one up to 90 degrees clockwise or anticlockwise
decoration.style.transform = `rotate(${(Math.random()*180)-90}deg)`;
});
}
catButton.addEventListener('click', dropDecs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment