Created
August 1, 2013 10:32
-
-
Save andilabs/6130236 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
<!--[if IE]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<style> | |
article, aside, figure, footer, header, hgroup, | |
menu, nav, section { display: block; } | |
body { | |
font-family: sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<p>Browser size: <span id="browserWidth"></span> <span id="browserHeight"></span></p> | |
<p>Mouse position: <span id="posDisplay"></span></p> | |
<p>Counter: <span id="counterDisplay"></span></p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function() { | |
var mousePos,windowSize, | |
posDisplay = document.getElementById("posDisplay"), | |
counterDisplay = document.getElementById("counterDisplay"), | |
counter = 0; | |
var viewportWidth = document.documentElement.clientWidth; | |
var viewportHeight = document.documentElement.clientHeight; | |
window.onmousemove = handleMouseMove; | |
setInterval(getMousePosition, 100); // setInterval repeats every X ms | |
function handleMouseMove(event) { | |
event = event || window.event; // IE-ism | |
mousePos = { | |
x: event.clientX, | |
y: event.clientY | |
}; | |
windowSize = { | |
x: document.documentElement.clientWidth, | |
y: document.documentElement.clientHeight | |
}; | |
} | |
function getMousePosition() { | |
var pos = mousePos; | |
var win = windowSize; | |
if (!pos) { | |
// We haven't seen any movement yet | |
pos = {x: "?", y: "?"}; | |
} | |
if (!windowSize){ | |
windowSize = {x: "?", y: "?"}; | |
} | |
posDisplay.innerHTML = "(" + pos.x + "," + pos.y + ")"; | |
counterDisplay.innerHTML = ++counter; | |
browserWidth.innerHTML=windowSize.x; | |
browserHeight.innerHTML=windowSize.y; | |
} | |
function display(msg) { | |
var p = document.createElement('p'); | |
p.innerHTML = msg; | |
document.body.appendChild(p); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment