Created
July 31, 2012 14:03
-
-
Save makotom/3217278 to your computer and use it in GitHub Desktop.
Simple scriptlet to examine Fitts's law
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> | |
<meta charset="UTF-8"> | |
<title>ergo3</title> | |
<style> | |
body{ | |
margin-left: 100px; | |
margin-right: 100px; | |
} | |
#sw{ | |
float: left; | |
background-color: #ff0; | |
width: 20px; | |
height: 20px; | |
margin-top: 230px; | |
margin-left: 0; | |
} | |
#target{ | |
float: left; | |
background-color: #f00; | |
height: 500px; | |
} | |
#border{ | |
clear: both; | |
} | |
</style> | |
<script> | |
window.addEventListener("DOMContentLoaded", function(){ | |
var time = 0, | |
sw = document.getElementById("sw"), tg = document.getElementById("target"), sv = document.getElementById("sv"), | |
setValueFn = function(){ | |
var swCPS = window.getComputedStyle(sw), tgCPS = window.getComputedStyle(tg); | |
tg.style.width = document.getElementById("wv").value + "px"; | |
tg.style.marginLeft = (parseFloat(document.getElementById("dv").value) - (parseFloat(tgCPS.width) / 2) + (parseFloat(swCPS.width) / 2)).toString() + "px"; | |
}, | |
feedbackFn = function(){ | |
var swCPS = window.getComputedStyle(sw), | |
tgCPS = window.getComputedStyle(tg), | |
dumpText = (parseFloat(tgCPS.marginLeft) + (parseFloat(tgCPS.width) / 2) - (parseFloat(swCPS.width) / 2)).toString() + "," + | |
parseFloat(tgCPS.width).toString() + "," + | |
(new Date().getTime() - time).toString(); | |
if(time === 0){ | |
return false; | |
} | |
document.getElementById("dump").value += dumpText + "\n"; | |
time = 0; | |
}; | |
tg.addEventListener("mouseup", feedbackFn, false); | |
sw.addEventListener("mousedown", function(){ | |
time = new Date().getTime(); | |
}, false); | |
sv.onsubmit = function(){ return false; }; | |
sv.addEventListener("submit", setValueFn, false); | |
setValueFn(); | |
}, false); | |
</script> | |
<div id="sw"></div> | |
<div id="target"></div> | |
<br id="border"> | |
<form id="sv"> | |
Distance: <input type="text" id="dv" value="500" size="4"> | |
Width: <input type="text" id="wv" value="50" size="4"> | |
<input type="submit" value="Set"> | |
</form> | |
<textarea id="dump"></textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment