Skip to content

Mobile Safari height wrong with address bar and tabs #2414

Description

@MickL

The height of a section is not set correctly on iOS Safari. You may try this out in Xcode Simulator. For example on iPhone 7 Plus the height of the viewport (without toolbar) is 370px, but the fullpage.js height of a section(set by $(window).height()) is 414px which includes the toolbar(address bar).

To show this i added a header and a footer which are positioned absolute (top:0 / bottom:0).

Initial:
bildschirmfoto 2016-11-17 um 18 40 15

Using $(window).scrollTop(1000):
bildschirmfoto 2016-11-17 um 18 40 34

A solution would be to use window.innerHeight. Interestingly it gives 414px (height with toolbar) on start, but with a timeout of 50ms it gives 370px (correct height without toolbar):

  1. Replace all $(window).height() with window.innerHeight
  2. Add a timeOut:
setTimeout(function () {
        $('.section').css('height', window.innerHeight + 'px');
        $(window).scrollTop(0);
    }, 50);
  1. Additionally we need to listen for window changes. For example on rotation sometimes the toolbar gets hidden. Or if the toolbar is hidden and we tap into top screen and the toolbar shows. Or when opening a new tab in iPhone Plus Landscape or on rotation:
$(window).on('resize', function() {
        $(window).scrollTop(0);
        $('.section').css('height', window.innerHeight + 'px');

        // Additional timeOut for iPhone Plus in landscape with multiple tabs opened
        setTimeout(function() {
            $('.section').css('height', window.innerHeight + 'px');
            $(window).scrollTop(0);
        }, 400);
    });

I added an additional timeOut within the on resize which only affects iPhone Plus with multiple tabs opened(tab bar visible). In this case again window.innerHeight is wrong until an amount of time. 400ms was the minimum i discovered.

With this 3 changes the height stays always perfect.

If not using the option verticalCentered: falsethe height changes needs to be done to .fp-tableCell, too.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions