Created
September 18, 2016 20:40
Star
You must be signed in to star a gist
Adds image anywhere on a webpage at every location someone clicks.
This file contains 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
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