Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Origame
Created March 27, 2017 07:38
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 Origame/8e732411cc9e05b1e60ff9b876658fac to your computer and use it in GitHub Desktop.
Save Origame/8e732411cc9e05b1e60ff9b876658fac to your computer and use it in GitHub Desktop.
JS - isMobile / isTablet / isDesk
//Global function
if (!window.Nsw) {
window.Nsw = {};
}
Nsw.viewPortWidth = function() {
var e = window, a = 'inner';
if (!('innerWidth' in window )) {
a = 'client';
e = document.documentElement || document.body;
}
return e[ a+'Width' ];
};
Nsw.isMobile = function () {
return Nsw.viewPortWidth() < 768;
};
Nsw.isTablet = function () {
return Nsw.viewPortWidth() >= 768 && Nsw.viewPortWidth() < 1024;
};
Nsw.isDesktop = function () {
return Nsw.isMobile() == false && Nsw.isTablet() == false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment