Skip to content

Instantly share code, notes, and snippets.

@neps-in
Created September 7, 2019 12:43
Show Gist options
  • Save neps-in/a16c1be803707dbf84cc26de2f292aa0 to your computer and use it in GitHub Desktop.
Save neps-in/a16c1be803707dbf84cc26de2f292aa0 to your computer and use it in GitHub Desktop.
How to find viewport height, viewport width using JavaScript
// This snippet will get the width, height of the viewport everytime you resize the browser window.
// The weight, height will be displayed on console window.
$(document).ready(function(){
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
console.info('Viewport W = ' + viewportWidth);
console.info('Viewport H = ' + viewportHeight);
$(window).resize(function() {
viewportWidth = $(window).width();
viewportHeight = $(window).height();
console.info('Viewport W = ' + viewportWidth);
console.info('Viewport H = ' + viewportHeight);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment