position: fixed doesn't work on iPad and iPhone

后端 未结 15 2079
一整个雨季
一整个雨季 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: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.

提交回复
热议问题