position: fixed doesn't work on iPad and iPhone

后端 未结 15 1882
一整个雨季
一整个雨季 2020-11-22 16:16

I have been struggling with fixed positioning in iPad for a while. I know iScroll and it does not always seem to work (even in their demo). I also know that Sencha has a fix

相关标签:
15条回答
  • 2020-11-22 16:47

    A lot of mobile browsers deliberately do not support position:fixed; on the grounds that fixed elements could get in the way on a small screen.

    The Quirksmode.org site has a very good blog post that explains the problem: http://www.quirksmode.org/blog/archives/2010/12/the_fifth_posit.html

    Also see this page for a compatibility chart showing which mobile browsers support position:fixed;: http://www.quirksmode.org/m/css.html

    (but note that the mobile browser world is moving very quickly, so tables like this may not stay up-to-date for long!)

    Update: iOS 5 and Android 4 are both reported to have position:fixed support now.

    I tested iOS 5 myself in an Apple store today and can confirm that it does work with position fixed. There are issues with zooming in and panning around a fixed element though.

    I found this compatibility table far more up to date and useful than the quirksmode one: http://caniuse.com/#search=fixed

    It has up to date info on Android, Opera (mini and mobile) & iOS.

    0 讨论(0)
  • 2020-11-22 16:50

    Fixed Footer (here with jQuery):

    if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' || navigator.platform == 'Linux armv6l') 
    {
        window.ontouchstart = function () 
        {
            $("#fixedDiv").css("display", "none");
        }
    
        window.onscroll = function() 
        { 
            var iPadPosition = window.innerHeight + window.pageYOffset-45; // 45 is the height of the Footer
             $("#fixedDiv").css("position", "absolute");
             $("#fixedDiv").css("top", iPadPosition);
             $("#fixedDiv").css("display", "block");
        }
    }
    
    // in the CSS file should stand:
    #fixedDiv {position: fixed; bottom: 0; height: 45px;  whatever else}
    

    Hope it helps.

    0 讨论(0)
  • 2020-11-22 16:52

    Had the same issue on Iphone X. To fixed it I just add height to the container

    top: 0;
    height: 200px;
    position: fixed;
    

    I just added top:0 because i need my div to stay at top

    0 讨论(0)
提交回复
热议问题