Skip to content

Instantly share code, notes, and snippets.

@steverydz
Created November 19, 2013 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steverydz/7554013 to your computer and use it in GitHub Desktop.
Save steverydz/7554013 to your computer and use it in GitHub Desktop.
Responsive JavaScript
function checkWidth() {
var viewportWidth = window.innerWidth;
// If the viewport width is greater than 640px
if (viewportWidth > 640) {
// Execute your code
} else {
// Do something else
}
}
(function () {
// Calls checkWidth function when page has loaded
checkWidth();
// Calls checkWidth function when window has been resized
window.onresize = checkWidth;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment