Created
March 27, 2017 07:38
-
-
Save Origame/8e732411cc9e05b1e60ff9b876658fac to your computer and use it in GitHub Desktop.
JS - isMobile / isTablet / isDesk
This file contains hidden or 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
//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