オブジェクト操作で

[新着] Webテンプレートを仮オープンしました



0   名前: Sagami : 2006/08/30(水) 12:17  ID:8W/508.Z
event.xなどを取得してマウスにオブジェクトが着いてくるウザいスクリプトがありますが、
あれって、画像オブジェクトでしか出来ないのでしょうか。絶対座標指定で<div>あ</div>
を動かそうとしても動作しません。
何かアドバイスをお願いします。

1   名前: sevi- : 2006/08/30(水) 12:17  ID:PQukhZTw
つまりこうだろうか.

<html>
<head>
<title>Untitled Page</title>
<script type="text/javascript">
<!--
function setCursor(obj)
{
	obj.style.position = "absolute";
	var fn_onmousemove = document.documentElement.onmousemove;
	document.documentElement.onmousemove = function(event)
	{
		if(fn_onmousemove != null)
			fn_onmousemove.apply(this, arguments);
		if(event == null) event = window.event;
		obj.style.left = (event.clientX - obj.offsetWidth / 2) + "px";
		obj.style.top = (event.clientY - obj.offsetHeight / 2) + "px";
	};
}
function initialize()
{
	setCursor(document.getElementById("cursor"));
	//setCursor(document.getElementById("cursor2"));
}
//-->
</script>
</head>
<body onload="initialize();">
<div id="cursor">あ</div>
<!--<div id="cursor2">い</div>-->
</body>
</html>

2   名前: Sagami : 2006/08/30(水) 12:17  ID:Oog3cRT7
sevi-さん、ありがとうございます。
つまり、そういうことでした。

一覧へ戻る