darkroomengineering / lenis

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

Any element that has vertical scroll is unscrollable with mousewheel #324

Closed Nodaysofff closed 8 months ago

Nodaysofff commented 8 months ago

To reproduce: 1) Create page with lenis and make one of the elements to have overflow: auto or overflow: scroll and to be scrollable vertically 2) Try to hover mouse over it and use mousewheel to scroll Fact: element scroll is ignored due to html or body wheel listener and instead of element scroll the whole page scrolls Expected behavior: Element should scroll to its end and only then page scroll should start (just like with overscroll-behavior: auto)

Supposed fix: Use a recursive function that traverses up the DOM tree to check overflow, something like this:

function hasScrollingAncestor(element) {
    if (!element.parentElement || element.parentElement.tagName.toLowerCase() === 'body') {
        return false;
    }
    const computedStyle = window.getComputedStyle(element.parentElement);
    if (computedStyle.overflow === 'scroll' || computedStyle.overflow === 'auto') {
        return true;
    } else {
        return hasScrollingAncestor(element.parentElement);
    }
}
clementroche commented 8 months ago

Can you share a codepen ?

Nodaysofff commented 8 months ago

Can you share a codepen ?

Sure: https://codepen.io/Nodaysofff/pen/XWQeJvg

You can comment whole js part to see the difference in scroll behaviour over the element with overflow

clementroche commented 8 months ago

you need data-lenis-prevent