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

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that don’t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now

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.

Quickstart image

Django MongoDB Backend Quickstart! A Step-by-Step Tutorial

Get up and running with the new Django MongoDB Backend Python library! This tutorial covers creating a Django application, connecting it to MongoDB Atlas, performing CRUD operations, and configuring the Django admin for MongoDB.

Watch full video →

👋 Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple “thank you” can uplift someone’s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay