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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay