Skip to content

Instantly share code, notes, and snippets.

@bencooper222
Created September 18, 2016 20:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bencooper222/8c79b7efbf06840f75d2163686c1bc7c to your computer and use it in GitHub Desktop.
Adds image anywhere on a webpage at every location someone clicks.
function createImage(coordinates){
var xPos = coordinates[0];
var yPos = coordinates[1];
var image = document.createElement("img");
image.src = ;// add image file reference here
// set their position
image.style.top = yPos + "px";
image.style.left = xPos + "px";
//duh
document.body.appendChild(image);
image.draggable = false; // this really should be done in CSS
console.log(xPos + yPos);
}
function getCursorPosition(){
var x = event.clientX; // Get the horizontal coordinate
var y = event.clientY; // get the vertical coordinate
var coordinates = [x,y];
return coordinates;
}
function removeText(text){
text.style.display = "none";
}
function main(){
var clickText = document.getElementById("clickText"); // get rid of the thing that says to click anywhere
removeText(clickText);
var coordinates = getCursorPosition();
createImage(coordinates);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment