logoalt Hacker News

mafik11/07/20240 repliesview on HN

Author here :) There is no trick here actually. It's just HTML / JS / CSS. Browsers are pretty good at compositing CSS transforms - and know how to handle DOM updates coming from event handlers & requestAnimationFrame. There is one CSS hint that speeds it up a little "will-change: transform". Another important ingredient is to update the object position in the (pointermove) event handler - so that the responsiveness is low - physics engines also could do this, but it's usually an overkill.

You can take a look at the script in the website's sources - it's inline.