日期:2014-05-16  浏览次数:20446 次

用js让透明的div跟着鼠标移动,兼容火狐和IE

废话不多说,代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
sfsdfsfsfsfsfsd<a id="item" href="#" onmouseout="move2(this)" onmousemove="move1(this)">给我出来,出来,出来</a> sfdsfsfsfsfsfsfdfs<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您能看见我吗?
<br>
<div id="f" style="display: none;color:blue;position:absolute;background-color: gray;filter: alpha(opacity=70); opacity: 0.7;">
	出来了出来了<br>出来了出来了<br>出来了出来了
<span id="span"></span>
</div>
</body>
<script type="text/javascript">
function mousePos(e){
	var x,y;
	var e = e||window.event;
	return {
		x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft, 
		y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop
	}; 
}
function move1(t,e) {
	onne(e,"");
	document.getElementById("span").innerText = t.innerText;
}
function move2(t,e) {
	onne(e,"none");
}
function onne(e,v) {
	var mouse = mousePos(e);     
	var t = document.getElementById("f")
	t.style.left = mouse.x ; 
	t.style.top = mouse.y; 
	t.style.display = v; 
}
</script>
</html>

?