iOS return bad value for window.innerHeight/Width

前端 未结 8 2042
悲哀的现实
悲哀的现实 2020-12-15 16:13

I\'m using window.innerHeight and window.innerWidth instructions to get the browser\'s available window size. It\'s working with firefox, safari (on a mac

相关标签:
8条回答
  • 2020-12-15 16:40

    Add

    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no">
    

    to the <head> element. That will fix the innerWidth issue.

    The retina has high density pixels - basically 4 hardware pixels to 1 logical pixel. That's why they report the same resolution.

    0 讨论(0)
  • 2020-12-15 16:46

    Also specify the height in the viewport meta tag according to this:

    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />

    I had problems with using jQuery $(window).height() on my iPad 2 (5.0.1) since I had missed out specifying the height in the meta tag. After adding it works much better.

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