2008. 11. 4. 11:42ㆍDevelopment Note
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>GoogleMapEffect</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
#div1
{
overflow: hidden;
position: absolute;
top: 100px;
left: 100px;
border : 5px solid #000;
width : 400px;
height : 350px;
}
img
{
border : 1px solid #000;
}
</style>
<script type="text/javascript">
var dragObject = null;
var mouseOffset = null;
document.onmousemove = mouseMove;
document.onmouseup = mouseUp;
function mousePoint(x,y)
{
this.x = x;
this.y = y;
}
function mousePosition(evnt)
{
var x = parseInt(evnt.clientX);
var y = parseInt(evnt.clientY);
return new mousePoint(x,y);
}
function getMouseOffset(target, evnt)
{
evnt = evnt || window.event;
var mousePos = mousePosition(evnt);
var x = mousePos.x - target.offsetLeft;
var y = mousePos.y - target.offsetTop;
return new mousePoint(x,y);
}
function mouseUp(evnt)
{
dragObject = null;
}
function mouseMove(evnt)
{
if(!dragObject) return;
evnt = evnt || window.event;
var mousePos = mousePosition(evnt);
if(dragObject)
{
dragObject.style.position = 'absolute';
dragObject.style.top = mousePos.y - mouseOffset.y + "px";
dragObject.style.top = mousePos.x - mouseOffset.x + "px";
return false;
}
}
function makeDraggable(item)
{
if(item)
{
item = document.getElementById(item);
item.onmousedown = function(evnt)
{
dragObject = this;
mouseOffset = getMouseOffset(this, evnt);
return false;
}
}
}
</script>
</head>
<body onload="makeDraggable('img1');">
<div id="div1">
<img id="img1" src="./image.jpg"/>
</div>
</body>
</html>