How to resolve position:fixed for a bottom toolbar on iOS (iPhone/iPad)

前端 未结 8 1722
礼貌的吻别
礼貌的吻别 2020-12-28 17:20

I have a bar that is fixed to the bottom of every page on my website by using position:fixed. The problem is that on devices like iPhone or iPad this property is not respect

相关标签:
8条回答
  • 2020-12-28 18:08

    Thank Google, not me:

    http://code.google.com/mobile/articles/webapp_fixed_ui.html

    Pretty simple, actually.

    0 讨论(0)
  • 2020-12-28 18:10

    Try hiding/displaying the bottom fixed nav on iPhone based on the window.innerHeight. Whenever the toolbars are displaying, usually when you scroll up, you can display the bottom nav and hide it when scrolling down, when the toolbars hide.

    You can use a code like this:

        var windowHeight = {
      small: window.innerHeight,
      middle: window.innerHeight,
      big: window.innerHeight
    }
    window.addEventListener('resize', function(){
      var currentHeight = window.innerHeight;
      if (currentHeight < windowHeight.small) {
        windowHeight.small = currentHeight;
      }
    
      if (currentHeight > windowHeight.big) {
        windowHeight.big = currentHeight;
      }
    
      console.log('windowHeight.small', windowHeight.small, 'windowHeight.middle', windowHeight.middle, 'windowHeight.big', windowHeight.big, 'currentHeight', currentHeight);
    
      if (currentHeight === windowHeight.big) {
        transform(stickyNav, 'translate3d(0,120%,0)');
        console.log('Hide bottom nav on big screen!');
      } else if (currentHeight === windowHeight.middle) {
        transform(stickyNav, 'translate3d(0,0,0)');
        console.log('Show bottom nav on middle screen!');
      } else {
        transform(stickyNav, 'translate3d(0,-100%,0)');
        console.log('Display bottom nav high up on smaller screen!');
      }
    })
    

    The transform(stickyNav, 'translate3d(x,x,x)') function is a simple function taking in the bottom nav and then applying a transform in order to hide/display an item placed at the bottom.

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