Created
June 1, 2017 08:14
-
-
Save seokju-na/1b1c2fe29d50c207eb321876d7c355c7 to your computer and use it in GitHub Desktop.
KWEB 5주차 예제 - position
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>mouse position</title> | |
<style> | |
#canvas{ | |
border:1px solid black; | |
height: 1000px; | |
} | |
.circle{ | |
border:1px solid red; | |
border-radius: 25px; | |
width: 50px; | |
height: 50px; | |
position: absolute; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>클릭 위치에 동그라미를 그립니다!</h1> | |
<div id="canvas"></div> | |
<script> | |
var $canvas = document.getElementById('canvas'); | |
function drawCircle(event) { | |
var left = event.clientX - 25; | |
var top = event.clientY - 25; | |
var $circle = document.createElement('span'); | |
$circle.classList.add('circle'); | |
$circle.style.left = left + 'px'; | |
$circle.style.top = top + 'px'; | |
$canvas.appendChild($circle); | |
} | |
$canvas.addEventListener('click', drawCircle); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment