자바스크립트 기본 예제(마우를 클릭드래그하여 오브젝트 이동 시키기)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

<style type="text/css">

#pop{ width: 100px; height: 100px; position: absolute; left: 100px; top: 100px; border: 1px solid #000000; background: #00FF00; z-index: 200;}

/* #은 #다음에 오는 id를 가진 객체만 사용 가능한 스타일*/

</style>

<script type="text/javascript">

var mx, my;

var on=0;

function move_onoff(e,chk){

var pop=document.getElementById("pop");

// offsetLeft,offsetTop : 부모요소를 기준한 좌표지점.

mx=e.clientX-pop.offsetLeft;

my=e.clientY-pop.offsetTop;

on=chk;

}

function move(e){

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

if(on==0)

return;

var pop=document.getElementById("pop");

var x=e.clientX-mx;

var y=e.clientY-my;

 

if(x>0)

pop.style.left=x+"px";

if(y>0)

pop.style.top=y+"px";

}

</script>

</head>

<body>

<div id="pop" onmousedown="move_onoff(event,1);" onmouseup="move_onoff(event,0);" onmousemove="move(event);"></div>

</body>

</html>



출처: https://tibang.tistory.com/entry/자바스크립트-기본-예제마우를-클릭드래그하여-오브젝트-이동-시키기 [T없이맑은날]

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
1 jQuery Mobile Form Example file 졸리운_곰 2018.09.04 428
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED