Skip to content

Instantly share code, notes, and snippets.

@zhuangya
Created April 3, 2012 16:14
Show Gist options
  • Save zhuangya/2293272 to your computer and use it in GitHub Desktop.
Save zhuangya/2293272 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<!-- nothing around here, just a simple demo for odvt. so, ignore me :) -->
<html>
<head>
<meta charset="utf-8">
<title>mouse move demo</title>
<style>
body {
background-color: #F5F5F5;
color: #333;
text-align: center;
text-shadow: 0 -1px 1px #AAA;
}
.ground {
width: 300px;
height: 300px;
background-color: skyblue;
outline: 1px solid #333;
margin: 20px auto;
}
</style>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(function() {
var $ground = $('#ground');
var $posX = $('#positionx');
var $posY = $('#positiony');
$ground.on('mousemove', function(event) {
$posX.text(event.pageX);
$posY.text(event.pageY);
});
});
</script>
</head>
<body>
<div class="ground" id="ground"></div>
the mouse position is:
<span id="positionx">x</span>,
<span id="positiony">y</span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment