欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-07 21:32:38
...

废话不多说,代码如下:

<!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>