Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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