Ilia Sidorenko
Ilia Sidorenko

Reputation: 2705

How to get viewport size in jquery-3?

$(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?

Upvotes: 0

Views: 2308

Answers (1)

Dhaarani
Dhaarani

Reputation: 1360

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();

});

Upvotes: 2

Related Questions