Skip to content

Instantly share code, notes, and snippets.

@codergautam
Created October 8, 2021 21:55
Show Gist options
  • Save codergautam/c3c0b2f4d2033b289db04e20ebe0b079 to your computer and use it in GitHub Desktop.
Save codergautam/c3c0b2f4d2033b289db04e20ebe0b079 to your computer and use it in GitHub Desktop.
Get the width and height of the viewport
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