0

$(window).height() used to return the height of the browser viewport window, and $(window).width() was used for browser window width.

$(window).height() now just returns the same value as $(document).height(), i.e. the height of the whole page.

What is a proper way to acquire viewport sizes now in jquery?

Ilia Sidorenko
  • 2,157
  • 3
  • 26
  • 30
  • according to these links http://api.jquery.com/height/, http://api.jquery.com/width/ and http://stackoverflow.com/questions/3044573/using-jquery-to-get-size-of-viewport using $(window).height() and $(window).width() is the correct way of getting the viewport. – Tim Kruger Sep 11 '16 at 05:00
  • weird, can't reproduce it anymore. indeed, those functions work fine. must have been some weird mix with bootstrap or other libraries possibly – Ilia Sidorenko Sep 18 '16 at 09:58

1 Answers1

2

To get the width and height of the viewport:

var viewportWidth = $(window).width();
var viewportHeight = $(window).height();

resize event of the page:

$(window).resize(function() {

    var viewportWidth = $(window).width();
    var viewportHeight = $(window).height();

});
Dhaarani
  • 1,350
  • 1
  • 13
  • 23