IT_Programming/JavaScript

[스크랩] 이미지 드래그해서 이동시키기

JJun ™ 2006. 8. 2. 09:43

<html>
<head>
<style>
<!--
.drag{position:relative;cursor:hand}
-->
</style>
<script language="JavaScript1.2">
<!--

var dragapproved=false
var z,x,y
function move(){
if (event.button==1&&dragapproved){
z.style.pixelLeft=temp1+event.clientX-x
z.style.pixelTop=temp2+event.clientY-y
return false
}
}
function drags(){
if (!document.all)
return
if (event.srcElement.className=="drag"){
dragapproved=true
z=event.srcElement
temp1=z.style.pixelLeft
temp2=z.style.pixelTop
x=event.clientX
y=event.clientY
document.onmousemove=move
}
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")
//-->
</script>
</head>
<body>
<b>미리보기 :</b> 이미지를 드래그해보세요 <br>
<img src="image7.gif" class="drag"><br>
</body>
</html>

출처 : ▶ 一人を ために◀
글쓴이 : 앙알앙알 원글보기
메모 :