知识库

跟随鼠标显示的十字星线及座标实时显示代码

来源: 本站    类别: 知识库    日期: 2016/6/1

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body style="margin: 0;">
 <div id="html"></div>
 <script type="text/javascript">
 //
 var ox = document.createElement('div');
 var oy = document.createElement('div');
  ox.style.width = '100%';
  ox.style.height = '1px';
  ox.style.backgroundColor = '#ddd';
  ox.style.position = 'fixed';
  ox.style.left = 0;
  document.body.appendChild(ox);
  oy.style.height = '100%';
  oy.style.width = '1px';
  oy.style.backgroundColor = '#ddd';
  oy.style.position = 'fixed';
  oy.style.top = 0;
  document.body.appendChild(oy);
 document.onmousemove = function(e){
  var e = e || event;
  var x = e.pageX;
  var y = e.pageY;
  ox.style.top = y + 'px';
  oy.style.left = x + 'px';
  document.getElementById('html'). innerHTML = 'x : ' + x + '<br/>y : ' + y;
 };
 </script>
</body>
</html>

相关文章


Copyright © 2004 - 2024 CNHWW Inc. All Rights Reserved
石家庄市征红网络科技有限公司版权所有 邮政编码:050051
服务电话:0311-85315152 13931185013 在线客服QQ:81447932 / 81447933 邮箱: cnhww@163.com