Safari in ios8 is scrolling screen when fixed elements get focus

前端 未结 12 1088
失恋的感觉
失恋的感觉 2020-12-12 11:24

In IOS8 Safari there is a new bug with position fixed.

If you focus a textarea that is in a fixed panel, safari will scroll you to the bottom of the page.

T

12条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 11:53

    Much like Mark Ryan Sallee suggested, I found that dynamically changing the height and overflow of my background element is the key - this gives Safari nothing to scroll to.

    So after the modal's opening animation finishes, change the background's styling:

    $('body > #your-background-element').css({
      'overflow': 'hidden',
      'height': 0
    });
    

    When you close the modal change it back:

    $('body > #your-background-element').css({
      'overflow': 'auto',
      'height': 'auto'
    });
    

    While other answers are useful in simpler contexts, my DOM was too complicated (thanks SharePoint) to use the absolute/fixed position swap.

提交回复
热议问题