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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On modal visible action #70

Closed
dimmuboy opened this issue Sep 18, 2021 · 4 comments
Closed

On modal visible action #70

dimmuboy opened this issue Sep 18, 2021 · 4 comments

Comments

@dimmuboy
Copy link

How can I do some action when user open modal with preferences?
I'm using fullPage.js so when I scroll in modal it scrolls my page on background instead modal. I would like to disable fullPage.js scrolling when modal is opened and enable it back when modal disappear.

@orestbida
Copy link
Owner

orestbida commented Sep 18, 2021

Hi @dimmuboy,

unfortunately, there is no built-in option to do such a thing. You can however use a MutationObserver — supported by all major browsers — to detect the open/closed state of the modal:

(function(){
    const html = document.documentElement;
    let isVisible = false, shouldShow = false;

    const observer = new MutationObserver(function() {
        shouldShow = html.className.indexOf('show--settings') > -1;

        if(!isVisible && shouldShow){
            isVisible = true;
            console.log("modal is visible")
        }else if(isVisible && !shouldShow){
            isVisible = false;
            console.log("modal is hidden")
        }
    });

    observer.observe(html, { 
        attributes: true, 
        attributeFilter: ['class']
    });
})();

@dimmuboy
Copy link
Author

Great @orestbida, it works! I'm able to to disable and enable fullpage.js back now.
But I still have problem scroll content inside preferences window. When I try to scroll it do nothing :/

https://dnmetalchrom.sk/

@orestbida
Copy link
Owner

based on fullPage.js, there's an option called normalScrollElements which sholud allow normal scrolling on specific elements. Try using it like this:

normalScrollElements: "#s-bl"

@dimmuboy
Copy link
Author

Awesome! It works, thanks

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

No branches or pull requests

2 participants