Mobile viewport height after orientation change

后端 未结 10 1444
孤街浪徒
孤街浪徒 2020-12-03 04:30

I am attaching a listener to the orientationchange event:

window.addEventListener(\'orientationchange\', function () {
    console.log(window.innerHeight);
}         


        
10条回答
  •  星月不相逢
    2020-12-03 04:55

    I solved this issue combining a couple of the above solutions. Resize would fire 4-5 times. Using .one, it fired too early. A short time out added to Christopher Bull's solution did the trick.

    $(window).on('orientationchange', function () {
      $(window).one('resize', function () {
        setTimeout(reference_to_function, 100);
      });
    });
    

提交回复
热议问题