Created
September 7, 2019 12:43
-
-
Save neps-in/a16c1be803707dbf84cc26de2f292aa0 to your computer and use it in GitHub Desktop.
How to find viewport height, viewport width using JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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