Skip to content

Instantly share code, notes, and snippets.

@craigblunden
Last active March 24, 2018 03:56
Show Gist options
  • Save craigblunden/e81c1e6b2730ba51da59ac38185d19d3 to your computer and use it in GitHub Desktop.
Save craigblunden/e81c1e6b2730ba51da59ac38185d19d3 to your computer and use it in GitHub Desktop.
Append dot on click event
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);
.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