-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
79 lines (74 loc) · 1.74 KB
/
index.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Heart Demo</title>
<style>
body {
background-color:#ddd;
}
canvas {
border: 1px solid #aaa;
background-color:#fff;
}
#enable {
border: 1px solid #000;
border-radius: 5px;
padding-left: 5px;
padding-right: 5px;
color: #333;
background-color: #eee;
font-weight:bold;
cursor:pointer;
}
#rate {
width: 400px;
}
</style>
</head>
<body>
<div id="heart"></div>
<div style="background-color:#fff">
<label for="rate">Pulse:</label>
<input id="rate" type="range" min="30" max="120" step="1" />
<span id="heartrate"></span>
</div>
<p>
<a id="enable">Enable</a> sound on mobile.
</p>
<!-- raf.js is a polyfill for requestAnimationFrame -->
<script type="text/javascript" src="lib/raf.js"></script>
<script type="text/javascript" src="js/heart.js"></script>
<script type="text/javascript">
var myHeart = new Heart({
target: '#heart'
});
var trackRange = false;
var rateInput = document.getElementById('rate');
var rateInfo = document.getElementById('heartrate');
var pulseHandler = function() {
var heartrate = rateInput.value*1;
myHeart.pulse(heartrate);
rateInfo.innerHTML = heartrate;
}
rateInput.addEventListener('change', pulseHandler, false);
rateInput.addEventListener('mousedown', function() {
trackRange = true;
}, false);
rateInput.addEventListener('mouseup', function() {
trackRange = false;
}, false);
rateInput.addEventListener('mousemove', function() {
if(trackRange) {
pulseHandler();
}
}, false);
rateInput.value = myHeart.heartrate;
rateInfo.innerHTML = myHeart.heartrate;
var enableMobile = document.getElementById('enable');
enableMobile.addEventListener('mouseup', function() {
myHeart.heartbeat();
}, false);
</script>
</body>
</html>