Last active
August 29, 2015 14:04
-
-
Save drejohnson/d08831f0b1a224bef562 to your computer and use it in GitHub Desktop.
Small javascript snippet for adding mobile CSS classes
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
/* ios only styling */ | |
.ios body { | |
background-color: #fff; | |
} | |
/* android only styling */ | |
.android body { | |
background-color: #e7e7e7; | |
} |
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
// https://coderwall.com/p/udfbcw | |
// By Sebastian Wallin | |
(function(d, l) { | |
for (var k in l) { | |
if(navigator.userAgent.match(new RegExp(l[k], 'i'))){ | |
d[k] = true; | |
d.documentElement.className+=' '+k; | |
} | |
} | |
}(document, { | |
ios: '(iPhone|iPod|iPad)', | |
android: 'android', | |
mobile: 'mobile', | |
webview: '(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)' | |
})); | |
if (document.ios) { | |
// Do ios specific stuff | |
} | |
else if (document.android) { | |
// Do Android specific stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment