Mobile Safari $(window).height() URL bar discrepancy

前端 未结 4 872
你的背包
你的背包 2020-12-05 15:47

I\'m trying to set a fixed div that\'s 100% the window height. But mobile safari doesn\'t detect the correct window height. It always thinks that the URL bar is part of the

4条回答
  •  一向
    一向 (楼主)
    2020-12-05 16:37

    This is due to a bug in jQuery's .height() method.

    To get the correct height you can use:

    $('#right-sidebar').height(window.innerHeight);
    

    To make sure you are mostly cross browser compatible you can do this:

    var height = window.innerHeight ? window.innerHeight : $(window).height();
    $('#right-sidebar').height(height);
    

    I say mostly as this will start to behave funny if there is a bottom scroll bar.

提交回复
热议问题