why is $(window).height() so wrong?

前端 未结 6 993
遥遥无期
遥遥无期 2020-12-10 11:21

I\'m trying to get the current browser viewport height, using

$(window).on(\'resize\',function() { 
  console.log(\"new height is: \"+$(window).height()); 
         


        
6条回答
  •  生来不讨喜
    2020-12-10 11:28

    One possible reason may be that you are checking the console with firebug/ something else. So that you don't get window height correct due to firebug height.

    You can try something like this:

    take a span/div in you document:

    
    

    and then

    $(window).on('resize',function() { 
      $('#res').html("new height is: "+$(window).height()); 
    });
    

    Or if you want to check out put on firebug console then detach it from browser and then check the result.

提交回复
热议问题