マウス座標を取得
マウス座標を取得
<html>
<head>
<script type="text/javascript" language="javascript" >
document.onmousemove = moveImage;
if(document.layers)
{
window.captureEvents(Event.MOUSEMOVE);
window.onmousemove = moveImage;
}
//マウス座標を取得
function moveImage(e)
{
if(document.all)
{
x = document.body.scrollLeft + event.clientX;
y = document.body.scrollTop + event.clientY;
}
else if(document.layers || document.getElementById)
{
x = e.pageX;
y = e.pageY;
}
moveLayer("img", x, y);
}
//レイヤーを動かす
function moveLayer(obj, x, y)
{
if(document.layers)
{
document[obj].left = x + 2;
document[obj].top = y + 2;
}
else if(document.all)
{
document.all(obj).style.pixelLeft = x + 2;
document.all(obj).style.pixelTop = y + 2;
}
else if(document.getElementById)
{
document.getElementById(obj).style.left = x + 2;
document.getElementById(obj).style.top = y + 2;
}
}
</script>
</head>
<body>
<form name=frm1 id=frm1 method="POST">
<div id ="img" style="position:absolute;width:50px;height:50px;">
<img src = "1.png">
</div>
</form>
</body>
</html>
|
|