JSFiddle - React, Tailwind, and code Playground
by Researcher
HTML
<!DOCTYPE html>
<html>
<head></head>
<body id="myid"></body>
</html>
JavaScript
// Edit to suit your needs.
var ADAPT_CONFIG = {
// Where is your CSS?
path: 'assets/css/',
// false = Only run once, when page first loads.
// true = Change on window resize and page tilt.
dynamic: true,
// First range entry is the minimum.
// Last range entry is the maximum.
// Separate ranges by "to" keyword.
range: [
'0px to 760px = mobile.min.css',
'760px to 980px = 720.css',
'980px = 960.css'
]
};
// Closure.
(function(w, d, config, undefined) {
// If no config, exit.
if (!config) {
return;
}
// Empty vars to use later.
var url, url_old, timer;
// Alias config values.
var callback = typeof config.callback === 'function' ? config.callback : undefined;
var path = config.path ? config.path : '';
var range = config.range;
var range_len = range.length;
// Create empty link tag:
// <link rel="stylesheet" />
// *** var css = d.createElement('link');
// *** css.rel = 'stylesheet';
// *** css.media = 'screen';
// Called from within adapt().
function change(i, width) {
// Set the URL.
//*** css.href = url;
//*** url_old = url;
printf(width);
// Call callback, if defined.
callback && callback(i, width);
}
// Adapt to width.
function adapt() {
// This clearTimeout is for IE.
// Really it belongs in react(),
// but doesn't do any harm here.
clearTimeout(timer);
// Parse browser width.
var width = w.innerWidth || d.documentElement.clientWidth || d.body.clientWidth || 0;
// While loop vars.
var arr, arr_0, val_1, val_2, is_range, file;
// How many ranges?
var i = range_len;
var last = range_len - 1;
while (i--) {
// Blank if no conditions met.
url = '';
// Turn string into array.
arr = range[i].split('=');
// Width is to the left of "=".
arr_0 = arr[0];
// File name is to the right of "=".
// Presuppoes a file with no spaces.
// If no file...