본문 바로가기

개발하자/자바스크립트

과제3(마우스클릭 좌표값을 이용해 div출력하기)

 

<html>
<head>
<style type="text/css">
div {
 position: absolute;
 width: 100px;
 height: 100px;
}

#s1 {
 background: pink;
 visibility: hidden;
}
</style>
<script>
 window.onload = function() {
  document.onmousedown = aa;
 }

 function aa() {
  s1.style.top = (event.y) + "px";
  s1.style.left = (event.x) + "px";
  s1.style.visibility = "visible";
 }
</script>
</head>
<body>
 <div id="s1"></div>
</body>
</html>