Code Monkey home page Code Monkey logo

Comments (6)

juliemoynat avatar juliemoynat commented on August 21, 2024

Adding this CSS on #js-modal should correct it:
-webkit-overflow-scrolling: auto !important;

from jquery-accessible-modal-window-aria.

nico3333fr avatar nico3333fr commented on August 21, 2024

Hi,

the only "CSS-only" solution I've found that is working on my iPad 2 is to set up position fixed on the body, it prevents scroll on iPad. However, the page under the modal is going to the top, so it is not satisfying. :-\

@juliemoynat I've tested it on my iPad 2, it is not working :-\

from jquery-accessible-modal-window-aria.

juliemoynat avatar juliemoynat commented on August 21, 2024

Hi,

Sometimes it works...

Also, if you have an "overflow: hidden" on the body, it doesn't work on Safari. You'll need to have it on an element inside...
Yes, "position: fixed" works and it's not the best solution.
I have no idea of what to do to have a better experience again...

from jquery-accessible-modal-window-aria.

alexmccabe avatar alexmccabe commented on August 21, 2024

This is how I disable scrolling across all devices.

class ScrollClass {
    constructor () {
        this.$body = $('body');

        this.styles = {
            disabled: {
                'height': '100%',
                'overflow': 'hidden',
            },

            enabled: {
                'height': '',
                'overflow': '',
            }
        };
    }

    disable ($element = $(window)) {
        let disabled = false;
        let scrollTop = window.pageYOffset;

        $element
            .on('scroll.disablescroll', (event) => {
                event.preventDefault();

                this.$body.css(this.styles.disabled);

                window.scrollTo(0, scrollTop);
                return false;
            })
            .on('touchstart.disablescroll', () => {
                disabled = true;
            })
            .on('touchmove.disablescroll', (event) => {
                if (disabled) {
                    event.preventDefault();
                }
            })
            .on('touchend.disablescroll', () => {
                disabled = false;
            });
    }

    enable ($element = $(window)) {
        $element.off('.disablescroll');

        this.$body.css(this.styles.enabled);
    }
}

export const Scroll = new ScrollClass();

Essentially, the meat of it is setting a variable to true on touchstart, check if the variable is true on touchmove and setting the variable to false on touchend.

from jquery-accessible-modal-window-aria.

jamiemitchell avatar jamiemitchell commented on August 21, 2024

Hi @alexmccabe How could I work this in with a click function for when a burger menu is open

I'm using this at the moment to add my body class

$('.site-header').on('click', '.menu-toggle', function(e) {

    e.preventDefault();

    $('body').toggleClass('no-scroll menu-open');

});

from jquery-accessible-modal-window-aria.

alexmccabe avatar alexmccabe commented on August 21, 2024
import Scroll from './path/to/ScrollClass';

$('.site-header').on('click', '.menu-toggle', function(e) {

    e.preventDefault();

    $('body').toggleClass('no-scroll menu-open');

    Scroll.disable();

});

from jquery-accessible-modal-window-aria.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.