darkroomengineering / lenis

How smooth scroll should be
https://lenis.darkroom.engineering
MIT License
8.58k stars 371 forks source link

scrollTo sometimes produces -1px offset on top when given HTMLElement as target #261

Closed Allaoua9 closed 6 months ago

Allaoua9 commented 10 months ago

This happens probably because of the Math.round :

https://github.com/studio-freight/lenis/blob/f359368b1aeb2b5cc5ca5b750bcbb74b4122d4f3/src/index.js#L332

Passing manually the scroll position and using Math.floor resolves this issue for me

const position = Math.floor(
        target.getBoundingClientRect().top + lenis.animatedScroll,
      );
lenis.scrollTo(position, {
        force: true,
        lock: true,
      });
clementroche commented 10 months ago

do you have a reproduction link ?

Allaoua9 commented 10 months ago

sorry no, I didn't have time to. I'll try and create a reproduction link

clementroche commented 6 months ago

i'm closing this because lack of activity