不需要計算DOM的動態文字排版:pretext
文字排版,甚至是文字與元素的動態互動,常常因繁瑣且頻繁地計算DOM,造成效能不佳。 然而,當Cheng Lou在twitter po出這篇文章時,所有前端人員都震驚了:只需要用數學方法觀察文字大小和字體計算換行符,「不需要去碰DOM的解決方案」,完全避開了Reflow惡夢。 My dear front-end developers (and anyone who’s interested in the future of interfaces): I have crawled through depths of hell to bring you, for the foreseeable years, one of the more important foundational pieces of UI engineering (if not in implementation then certainly at… pic.twitter.com/BKnwCDIp75 — Cheng Lou (@_chenglou) March 28, 2026 你可以查看此篇文的各方高手引用實作,就能看出這是多麼劃時代的解決方案。金字塔、文繞圖(圖片會動)、Bad Apple動畫等文字排版完美解決且非常順暢,在文章中玩Air Hockey也沒有問題。 Cheng Lou也把pretext技術開源放到 github ,你也能親自發揮你的創意體驗一下它的強大。 Riding the wave of the pretext.js without pretext 😅 pic.twitter.com/D8CAAZqcpJ — Felix Martinez (@Sirokos) March 30, 2026 上面是有人用pretext.js實作的衝浪效果。不怕做不到,只怕沒創意靈感。
