Skip to content

Commit 4569126

Browse files
committed
smoother animations
1 parent b957f97 commit 4569126

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

DisplayClient/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const hr = document.getElementById("hr")
22
const heartImg = document.getElementById("pulsingheart")
33
let isConnected = false;
4+
let currentHR = 0;
45

56
const params = new URLSearchParams(window.location.search);
67
const ip = params.get("ip") || "localhost";
@@ -16,16 +17,22 @@ function connect() {
1617
socket.addEventListener('message', function (event) {
1718
var message = JSON.parse(event.data);
1819
if (message.hr) {
20+
let spb = 1/(message.hr/60);
21+
if (currentHR == 0) heartImg.style.animation = "pulse " + spb + "s infinite";
1922
hr.innerText = message.hr;
20-
var spb = 1/(message.hr/60)
21-
heartImg.style.animation = "pulse " + spb + "s infinite"
23+
currentHR = message.hr;
2224
}
2325
});
26+
heartImg.addEventListener('animationiteration', () => {
27+
let spb = 1/(currentHR/60);
28+
heartImg.style.animation = "pulse " + spb + "s infinite";
29+
});
2430
}
2531

2632
function resetConnection() {
2733
hr.innerText = "0";
2834
heartImg.style.animation = "";
35+
currentHR = 0
2936
isConnected = false;
3037
}
3138

0 commit comments

Comments
 (0)