https://codesandbox.io/s/nostalgic-cherry-wwpzj?file=/src/in...
(I made the exact same thing last year as a joke for our team monitors)
On a technical note, not that there’s much you can do about this, but because you’re reading clientWidth and clientHeight each frame, you’re forcing reflow. A performant implementation would probably require avoiding the DOM altogether within the draw loop, so that would mean using canvas/webgl.
For science, I went ahead and converted the code to ES3 and ran on the 10-year old first generation iPad (with setInterval) and it's still pretty smooth.
EDIT: I added a simple rate-limiting function :)
No wonder modern frontend is such a mess.
I beleieve you are quite competent in this, so for me it's just another illustration of how HTML/DOM ecosystem is broken in so many ways that it takes enormous effort to perform such a trivial task. Thank you and plase stop wasting your time on this)
> Thank you and please stop wasting your time on this
Haha. Thanks. I like these mini-challenges, helps me relax for a few minutes :)
I think adding `will-change: transform` might help a bit, to hint the user agent that you'll be animating transforms...
This probably wasn't the case with DVD players (because the effort wouldn't have been worth it for a mass market consumer product) but 1980s Amiga home computers for example in some regard still outperformed mid-1990s PCs, which nominally were several orders of magnitude faster.
They were able to pull this off by clever hardware tricks and due to custom chips that were highly optimised for very specific use cases.
Run-of-the-mill PCs on the other hand were standardised and designed to perform good on average in most situations, not just very specific ones.
Or use canvas and this won't be a matter of DOM manipulation.