1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test cursor pos</title>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("prototype", "1.6.1.0");
</script>
<script type="text/javascript">
function whereAmI(e) {
$("message").update("Capturé par " + e.element().identify() + ";X:" + e.pointerX() + ";Y:" + e.pointerY());
$("axisX").setStyle({left: e.pointerX() + "px"});
$("axisY").setStyle({top: e.pointerY() + "px"});
e.stop();
}
Event.observe(window, "load", function() {
$("axisX").setStyle({height: document.viewport.getHeight() + "px"});
$("axisY").setStyle({width: document.viewport.getWidth() + "px"});
$$("div").invoke("observe", "click", whereAmI);
});
</script>
<style type="text/css">
.coord {
left:0;
top:0;
position:absolute;
background-color: blue;
z-index:1000;
}
#axisX {
width:1px;
}
#axisY {
height:1px;
}
</style>
</head>
<body>
<span id="message">Message</span>
<div style="margin-top:20px;padding-left:30px;background-color:red;" id="red">
<div style="position:relative;top:20px;left;30px;background-color:yellow" id="yellow">
</div>
<div style="position:relative;width:300px;height:180px;background-color:orange;" id="orange">
<div style="position:absolute;bottom:20px;right:30px;background-color:green;width:50px;height:50px;" id="green">
</div>
</div>
<div style="position:relative;width:300px;height:180px;background-color:maroon;float:left" id="maroon">
<div style="background-color:gold;width:50px;height:50px;float:right;overflow:scroll" id="gold">
<div style="margin-top:50px;height:20px;width:20px;background-color:pink" id="pink">
</div>
</div>
</div>
</div>
<div id="axisX" class="coord"></div>
<div id="axisY" class="coord"></div>
</body>
</html> |
Partager