Created
December 14, 2018 11:17
-
-
Save alicethewhale/71d77432d958e8a5c85f7ff39694246c 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
const decSelector = document.querySelector('.decorations'); | |
const tree = document.querySelector('.tree-container'); | |
function placeDecoration(e) { | |
if (decSelector.value !== "") { | |
const decoration = document.createElement('div'); | |
decoration.textContent = decSelector.value; | |
decoration.classList.add('decoration'); | |
// minus 15 to account for the decorations’ size of 30px | |
decoration.setAttribute("style", `top: ${e.clientY}px; left: ${e.clientX - 15}px;`); | |
tree.appendChild(decoration); | |
decoration.setAttribute("x", `${e.clientY}`); | |
decoration.setAttribute("y", `${e.clientX}`); | |
tree.appendChild(decoration); | |
} | |
} | |
tree.addEventListener('click', placeDecoration); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment