JS实现网页十字光标

<html>
<head>
<title>在页面中显示十字光标</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<div id="divleft"></div>
<div id="divtop"></div>
<script language="JavaScript">
function move(){
 if (event.clientX<document.body.clientWidth-2)
  divtop.style.pixelLeft=document.body.scrollLeft+event.clientX+1;
 else divtop.style.pixelLeft=document.body.clientWidth-2;
 if (event.clientY<document.body.clientHeight-2)
  divleft.style.pixelTop=document.body.scrollTop+event.clientY+1;
}
function setstyle(n){
 var name=eval(n).style;
 name.position="absolute";
 name.left="0";
 name.top="0";
 if (n=="divleft"){
  name.height="2px";
  name.width=document.body.clientWidth;
 }
 if (n=="divtop"){
  name.width="2px";
  name.height=document.body.clientHeight;
 }
 name.backgroundColor="#6699cc";
 name.fontSize="0px";
}
setstyle("divleft");
setstyle("divtop");
document.onmousemove=move;
</script>
</body>
</html>

posted @ 2017-08-24 14:35  代号 11  阅读(758)  评论(0编辑  收藏  举报