DEV Community

iDev-Games
iDev-Games

Posted on • Edited on

2

📱 How to Create a GitHub-Style Floating Header with Trig.js

Ever noticed how GitHub’s mobile app keeps the page repo details visible in a floating header as you scroll? It’s a slick UX touch that enhances navigation. In this post, I’ll show you how to achieve the same effect using Trig.js, the lightweight and ultra-fast scroll animation library.

Why Use Trig.js for Scroll Animations?
Most AOS (Animation on Scroll) libraries rely heavily on JavaScript for animations, which can impact performance. Trig.js is different—it’s CSS-based, meaning it leverages the browser’s GPU for smoother, more efficient animations.

✅ Why Trig.js?
⚡ Lightweight (~4KB) → No bloated dependencies
🎯 Optimized for scroll performance → No jank, no lag
🎨 Pure CSS scroll animations → Faster than JS-heavy alternatives
🏆 Best AOS alternative → Simple, powerful, and built for modern web apps
🛠️ Building the Floating Header Effect

🚀 Why Trig.js is the Best AOS Library for This?

Feature Trig.js 🏆 AOS.js ScrollTrigger (GSAP)
Lightweight (~4KB) ❌ (~6KB) ❌ (100KB+)
CSS-based (Fastest) ❌ (JS-heavy)
Easy Setup ❌ (Complex)
Predefined Animations

🏁 Final Thoughts
Trig.js makes it ridiculously easy to create scroll-based animations with zero JavaScript complexity. Whether you’re building sticky headers, fade-ins, or full-page animations, it’s the best AOS alternative in 2025.

Why not have a look at our Trig.js AOS tutorial and give it ago for yourself.

💬 What do you think? Would you use this in your project? Let me know in the comments! 👇

🔗 Try Trig.js Today | Docs | GitHub Repo

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (5)

Collapse
 
besworks profile image
Besworks • Edited

IntersectionObserver was definitely the right API to base this on. Nice to see it starting to pop up in the wild. I wrote few custom-elements with it back in 2021 and your lib is the first example I've seen of someone else even discussing this technique. Good job!

Collapse
 
idevgames profile image
iDev-Games • Edited

Thanks! I'm not using it in the conventional way it was designed to be used however it's the only way I can achieve avoiding reflows and get element position data on every scroll. It's great to be able to open this API up to other developers to use in endless creative ways.

Collapse
 
besworks profile image
Besworks

Yes, it works very well for triggering animations in either scroll direction without inefficient polling. I use it on my own homepage for this same purpose.

Thread Thread
 
idevgames profile image
iDev-Games • Edited

I don't just use it for triggering animations though. I use it to calculate element position data. I pass that to the front end as CSS variables so you can create dynamic scroll animations like in the docs. So I'm not really using it as efficiently as I should be but after 30 versions, I think it is as optimised as I'll get it for the most part.

Thread Thread
 
besworks profile image
Besworks

Ah, yes I see now, the animation state is based entirely on scroll position, not just triggered by it. Very interesting usage.

Cloudinary image

📊 Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay