Created
October 8, 2021 21:55
-
-
Save codergautam/c3c0b2f4d2033b289db04e20ebe0b079 to your computer and use it in GitHub Desktop.
Get the width and height of the viewport
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
function viewport() | |
{ | |
var e = window | |
, a = 'inner'; | |
if ( !( 'innerWidth' in window ) ) | |
{ | |
a = 'client'; | |
e = document.documentElement || document.body; | |
} | |
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] } | |
} | |
/* | |
USAGE: | |
var width = viewport().width | |
var height = viewport().height | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment