forked from enrod92/jsCircles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
executable file
·35 lines (26 loc) · 752 Bytes
/
demo.html
File metadata and controls
executable file
·35 lines (26 loc) · 752 Bytes
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
<html>
<head>
<title>Javascript Box - OOP demo</title>
</head>
<body>
Demonstrating how you can detect how long your mouse was clicked or held down. Open your console to see how it works.
<script>
//using immediate function to avoid global variable issues
( function(){
var mousedown_time;
function getTime(){
var date = new Date();
return date.getTime();
}
document.onmousedown = function(e){
mousedown_time = getTime();
}
document.onmouseup = function(e){
time_pressed = getTime() - mousedown_time;
console.log('You held your mouse down for', time_pressed, 'miliseconds.');
}
//technically we don't even need the mousedown variable but we're leaving it there for now..
})();
</script>
</body>
</html>