Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to prevent scroll #334

Closed
mickaelchanrion opened this issue May 14, 2024 · 6 comments
Closed

Add function to prevent scroll #334

mickaelchanrion opened this issue May 14, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@mickaelchanrion
Copy link
Contributor

mickaelchanrion commented May 14, 2024

Hi there 馃憢

data-lenis-prevent is very useful to allow nested scroll but in some peculiar cases, we don't have the control over an element that is expected to be scrollable so no way to add this attribute.

Here is an example: a third party cookie modal for fine grained controls.

image

In this situation this element is generated by their script and they do not provide events on modal triggering so I don't really see how I can add the attribute. Here is a solution I could think of:

new Lenis({
  // Prevent scroll on any `.foo` element
  preventScroll: (node) => {
    return node.classList.contains('foo')
  }
})

I can propose a PR for that :)

@clementroche
Copy link
Member

hi @mickaelchanrion, good idea ! Do you know if these modals always use the same classes ?

@mickaelchanrion
Copy link
Contributor Author

Hi Clement,
I guess yes, in 99% of cases.
If we want to cover every potential situation, we could define preventScroll this way:

type LenisOptions = {
  // ...
  preventScroll?: string[] | (node: Element) => boolean
}

@clementroche clementroche added the enhancement New feature or request label May 27, 2024
@clementroche
Copy link
Member

clementroche commented May 30, 2024

hey @mickaelchanrion what service provides this cookie modal and what class is used ? I wanna provide an example in the documentation

@clementroche
Copy link
Member

@mickaelchanrion should be available in v1.1.0

@mickaelchanrion
Copy link
Contributor Author

@clementroche Great news!!

Regarding your question, you can open this link: https://www.cookieyes.com/
You'll see a cookie banner. Click on customize and a modal will appear. This modal .cky-modal contains scrollable elements such as .cky-iab-detail-sub-wrapper.

After checking the v1.1.0, a correct example could be:

new Lenis({
  prevent: (node) => node.classList.contains('cky-modal')
})

@clementroche
Copy link
Member

clementroche commented Jun 3, 2024

Exact @mickaelchanrion, does it suits your needs ? If so i'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants