Smooth scrolling with sticky elements

Hey guys,

I’ve built a site where I use Lottie animations which are triggered by using Webflows Interaction “While scrolling in view”.
Now I’m trying to implement smooth scrolling on the website, but for some reason this messes up my sticky sections. I’ve used Webflow Smooth Scroll (Luxy.js) - Webflow


How it behaves:

Here is my share link: https://preview.webflow.com/preview/smooth-scrolling-with-sticky-elements?utm_medium=preview_link&utm_source=designer&utm_content=smooth-scrolling-with-sticky-elements&preview=bf0e0b6c456953d9f10bafbc1ee734d2&mode=preview


What I already tried:

Is there anything else I can try or use in order to make smooth scrolling work with sticky elements?

1 Like

I’m glad I’m not the only one. Let me know if you find a solution! I would greatly appreciate it.

Did you ever find a solution to this? I’m struggling with this at the moment

1 Like

I have the same problem, is there a way to implement smooth scrolling differently if this keeps messing up the sticky elements?

I believe using Timothy Rick’s Locomotive Scroll in place of the Luxy.js Weblfow Smooth Scroll will still allow you to utilize fixed and sticky positioned elements.

Here is the video on YouTube:

Quick Note:
There may be a newer video by Timothy Ricks but this is one that I stumbled accross.

Hi, I’ve recently facing similar problem, usually most of us facing the same problem which is :

  • wants to create a smooth experience while scrolling
  • trying to implement luxy.js or locomotive.js but the animation that related to page view (sticky, etc.) is no longer working because of those code.

I’ve tried using locomotive.js for sticky and for some reason, idk why but it won’t work (but this should have work, idk why it doesn’t on my project), but my other animation such as show/hide Nav bar while scrolling is affected and it became not working.

after searching for hours I’ve found this magnificent code, it’s called Lenis.js, this code is different than the other two mentioned before because this doesn’t need a div block with a class wrapping all the content of the page. This code is very easy to use and also doesn’t affect any of the animation we built in webflow.

The downside of Locomotive Scroll is that tools such as Webflow don’t receive the correct scroll position. A correct scroll position is required in order to correctly display scroll animations. Hence the oftentimes buggy results.

However, Lenis doesn’t seem to hijack the user’s native scroll at all, but instead (in some genius way that I haven’t been able to identify how) seems to put an easing or smoothing on the native scroll while still delivering the correct scroll position to whatever software or code that needs it.

This quote above is a great summary of Lenis, from the writer of the blog that I found this treasure information, you can read it here Smooth Scrolling Using Lenis

Here is the GitHub of Lenis, Lenis GitHub

and if you want to just copy and paste the code on webflow, you can use this code that I’ve modify a little bit for webflow :

<script src="https://cdn.jsdelivr.net/gh/studio-freight/lenis@0.2.28/bundled/lenis.js"></script>

<script>
const lenis = new Lenis({
  duration: 1.2,
  easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
  direction: 'vertical', // vertical, horizontal
  gestureDirection: 'vertical', // vertical, horizontal, both
  smooth: true,
  mouseMultiplier: 1,
  smoothTouch: false,
  touchMultiplier: 2,
  infinite: false,
})

//get scroll value
lenis.on('scroll', ({ scroll, limit, velocity, direction, progress }) => {
  console.log({ scroll, limit, velocity, direction, progress })
})

function raf(time) {
  lenis.raf(time)
  requestAnimationFrame(raf)
}

requestAnimationFrame(raf)
</script>

How to use it : just copy and paste on the page you want to scrolled smoothly!

Hope this help anyone that needed it :grin:

5 Likes

Thank you so much, this has saved me more than a day’s headache. This works 100%.

Worked for me too! I replaced the Luxy.js with Juan’s Lenis.js code. Thank you @Juan_Prima! You saved the day.

THANK YOU!!
Solved the problem of not being able to use Sticky position with luxy.js Smooth Scroll!

You are a legend! It works perfectly!