metafizzy / flickity-fullscreen

Enable fullscreen view for Flickity carousels
46 stars 17 forks source link

Fullscreen body scroll issue #3

Open schellenbergk opened 6 years ago

schellenbergk commented 6 years ago

When in fullscreen user can scroll the body when swiping up/down on the fullscreen overlay.

schellenbergk commented 6 years ago

Is there a way to extend fullscreen functionality to add a custom body class?

desandro commented 6 years ago

Thanks for reporting this issue. What device / browser are you testing with? This might be related to metafizzy/flickity#740

schellenbergk commented 6 years ago

Latest chrome on ios (iphone x). Also happens on latest safari ios.

desandro commented 6 years ago

Okay, I'll have to take a look.

benjibee commented 6 years ago

I'm coming across this issue now in my development. I have some slides that contain text and the user can scroll vertically to read this, or horizontally to navigate slides. Using the latest Safari and Firefox for iOS the background scrolls once the user hits the bottom of the slide.

quangnhattran commented 5 years ago

Hi @desandro You have any idea on how to resolve this matter? Thanks :)

petercarsater commented 5 years ago

I used a solution suggested at stackoverflow.

$carousel.on( 'fullscreenChange.flickity', function( event, isFullscreen ) {

    if (isFullscreen) {

        var _overlay = document.querySelector('.flickity-enabled.is-fullscreen');
        var _clientY = null; // remember Y position on touch start

        _overlay.addEventListener('touchstart', function (event) {
            if (event.targetTouches.length === 1) {
                // detect single touch
                _clientY = event.targetTouches[0].clientY;
            }
        }, false);

        _overlay.addEventListener('touchmove', function (event) {
            if (event.targetTouches.length === 1) {
                // detect single touch
                disableRubberBand(event);
            }
        }, false);

        function disableRubberBand(event) {
            var clientY = event.targetTouches[0].clientY - _clientY;

            if (_overlay.scrollTop === 0 && clientY > 0) {
                // element is at the top of its scroll
                event.preventDefault();
            }

            if (isOverlayTotallyScrolled() && clientY < 0) {
                //element is at the top of its scroll
                event.preventDefault();
            }
        }

        function isOverlayTotallyScrolled() {
            // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
            return _overlay.scrollHeight - _overlay.scrollTop <= _overlay.clientHeight;
        }

    }

});