#Laggy website
5 messages · Page 1 of 1 (latest)
Based on the tiny portion of visible code, I infer what you need is a keydown even listener on the document.
Note that this approach should be used even if you have a fast computer. Your technique is never considered the correct way regardless of the computer.
This is not the purpose of requestAnimationFrame(). Its purpose is to let you update the visuals immediately before a repaint. The DOM has a set of events that elements can listen too. They were invented for the sole purpose of efficiently responding to user activity without the need to poll.
Can use InteractionObserverAPI too. it's beetter.
That depends on the specific change that you are trying to respond to. The Intersection observer is useful to detect when something comes into or out of view. It is unclear from the screenshot if that is in any way related to what the OP is trying to do.