Created
December 1, 2016 15:18
-
-
Save dipakcg/3e34956e05e9ece6f52bed6e921e4818 to your computer and use it in GitHub Desktop.
Get browser window size using jQuery (useful for responsive web design)
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Get browser window size using jQuery (useful for responsive testing)</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(window).bind({ | |
load:function(){ | |
var windowSize = $(window).width(); | |
$('p.window-width').text('Window width = ' + windowSize + 'px'); | |
}, | |
resize:function(){ | |
var windowSize = $(window).width(); | |
$('p.window-width').text('Window width = ' + windowSize + 'px'); | |
}, | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>Resize your browser window to get width:</h1> | |
<p class="window-width"></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment