Last active
August 29, 2015 14:22
-
-
Save apacsa/3bc56b967a9de97e5e58 to your computer and use it in GitHub Desktop.
This JS code checks the width of the browser window, and loads the according stylesheet variant. Stylesheet variants are differentiated by a two-letter suffix (-tn, -xs, -sm, -md, -lg, -xl, -xx). These are standard Bootstrap screen-sizes, with some extensions added from: https://github.com/webprom/bootstrap-layout-xl-xxl/blob/master/bootstrap-xl…
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
/* | |
* author: arpad1976@gmail.com | |
* 2015-06-02 | |
*/ | |
var windowWidth = window.innerWidth; | |
var windowWidth = window.innerWidth; | |
if (windowWidth >= 1920) { | |
styleSheetVariant = '-xx'; | |
} else if (windowWidth >= 1440 && windowWidth < 1920) { | |
styleSheetVariant = '-xl'; | |
} else if (windowWidth >= 1200 && windowWidth < 1440) { | |
styleSheetVariant = '-lg'; | |
} else if (windowWidth >= 992 && windowWidth < 1200) { | |
styleSheetVariant = '-md'; | |
} else if (windowWidth >= 768 && windowWidth < 992) { | |
styleSheetVariant = '-sm'; | |
} else if (windowWidth >= 480 && windowWidth < 768) { | |
styleSheetVariant = '-xs'; | |
} else if (windowWidth >= 320 && windowWidth < 480) { | |
styleSheetVariant = '-tn'; | |
} | |
var head = document.getElementsByTagName('head')[0]; | |
var link = document.createElement('link'); | |
link.rel = 'stylesheet'; | |
link.href = 'cssFolder/cssFilename-'+styleSheetVariant+'.css'; | |
link.media = 'screen'; | |
head.appendChild(link); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment