六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 34|回复: 0

pageX\pageY & layerX\layerY

[复制链接]

升级  62%

7

主题

7

主题

7

主题

童生

Rank: 1

积分
31
 楼主| 发表于 2013-2-7 17:12:26 | 显示全部楼层 |阅读模式
<html><head><title>pageX\pageY & layerX\layerY example</title><script type="text/javascript">function showCoords(evt){  var form = document.forms.form_coords;  var parent_id = evt.target.parentNode.id;  form.parentId.value = parent_id;  form.pageXCoords.value = evt.pageX;  form.pageYCoords.value = evt.pageY;  form.layerXCoords.value = evt.layerX;  form.layerYCoords.value = evt.layerY;}</script><style type="text/css"> #d1 {  border: solid blue 1px;  padding: 20px; } #d2 {  position: absolute;  top: 180px;  left: 80%;  right:auto;  width: 40%;  border: solid blue 1px;  padding: 20px; } #d3 {  position: absolute;  top: 240px;  left: 20%;  width: 50%;  border: solid blue 1px;  padding: 10px; }</style></head><body onmousedown="showCoords(event)"><p>To display the mouse coordinates please click anywhere on the page.</p><div id="d1"><span>This is an un-positioned div so clicking it will returnlayerX/layerY values almost the same as pageX/PageY values.</span></div><div id="d2"><span>This is a positioned div so clicking it will return layerX/layerYvalues that are relative to the top-left corner of this positionedelement. Note the pageX\pageY properties still return theabsolute position in the document, including page scrolling.</span><span>Make the page scroll more! This is a positioned div so clicking itwill return layerX/layerY values that are relative to the top-leftcorner of this positioned element. Note the pageX\pageY properties stillreturn the absolute position in the document, including pagescrolling.</span></div><div id="d3"><form name="form_coords"> Parent Element id: <input type="text" name="parentId" size="7" /><br /> pageX:<input type="text" name="pageXCoords" size="7" />   pageY:<input type="text" name="pageYCoords" size="7" /><br /> layerX:<input type="text" name="layerXCoords" size="7" />   layerY:<input type="text" name="layerYCoords" size="7" /></form></div></body></html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表