Last active
March 24, 2018 03:56
-
-
Save craigblunden/e81c1e6b2730ba51da59ac38185d19d3 to your computer and use it in GitHub Desktop.
Append dot on click event
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 el = document.createElement("<div class='dot'></div>"); | |
function addDot(e){ | |
let clientX = e.clientX; | |
let clientY = e.clientY; | |
let el = document.createElement("div"); | |
el.classList.add('dot') | |
el.setAttribute("style", `top: ${clientY-10}px; left: ${clientX-10}px`); | |
let dom = document.querySelector("body"); | |
dom.append(el) | |
} | |
document.addEventListener('click', addDot); |
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
.dot { | |
height: 20px; | |
width: 20px; | |
border-radius: 50%; | |
background: red; | |
position: absolute; | |
z-index: 20; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment