diff --git a/oneko.js b/oneko.js index bd8b882..aa0b8c0 100644 --- a/oneko.js +++ b/oneko.js @@ -105,6 +105,11 @@ document.body.appendChild(nekoEl); + document.addEventListener("wheel", function (event) { + nekoPosY += event.deltaY / 10; + updatePos(); + }); + document.addEventListener("mousemove", function (event) { mousePosX = event.clientX; mousePosY = event.clientY; @@ -124,8 +129,8 @@ lastFrameTimestamp = timestamp; } if (timestamp - lastFrameTimestamp > 100) { - lastFrameTimestamp = timestamp - frame() + lastFrameTimestamp = timestamp; + frame(); } window.requestAnimationFrame(onAnimationFrame); } @@ -231,8 +236,12 @@ nekoPosX = Math.min(Math.max(16, nekoPosX), window.innerWidth - 16); nekoPosY = Math.min(Math.max(16, nekoPosY), window.innerHeight - 16); - nekoEl.style.left = `${nekoPosX - 16}px`; - nekoEl.style.top = `${nekoPosY - 16}px`; + updatePos(); + } + + function updatePos() { + nekoEl.style.left = `${nekoPosX - 16}px`; + nekoEl.style.top = `${nekoPosY - 16}px`; } init();