JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://refreshless.com/noUiSlider/distribute/nouislider.js?v=900"></script>
<script src="https://refreshless.com/nouislider/documentation/assets/wNumb.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<link rel="stylesheet" href="https://refreshless.com/noUiSlider/distribute/nouislider.css?v=900">
<div class="budget-slider" id="budget-slider"></div>
CSS
/*! nouislider - 9.0.0 - 2016-09-29 21:44:02 */
/* Functional styling;
* These styles are required for noUiSlider to function.
* You don't need to change these rules to apply your design.
*/
.noUi-target,
.noUi-target * {
-webkit-touch-callout: none;
-webkit-user-select: none;
-ms-touch-action: none;
touch-action: none;
-ms-user-select: none;
-moz-user-select: none;
user-select: none;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.noUi-target {
position: relative;
direction: ltr;
}
.noUi-base {
width: 100%;
height: 100%;
position: relative;
z-index: 1; /* Fix 401 */
}
.noUi-connect {
position: absolute;
right: 0;
top: 0;
left: 0;
bottom: 0;
}
.noUi-origin {
position: absolute;
height: 0;
width: 0;
}
.noUi-handle {
position: relative;
z-index: 1;
}
.noUi-state-tap .noUi-connect,
.noUi-state-tap .noUi-origin {
-webkit-transition: top 0.3s, right 0.3s, bottom 0.3s, left 0.3s;
transition: top 0.3s, right 0.3s, bottom 0.3s, left 0.3s;
}
.noUi-state-drag * {
cursor: inherit !important;
}
/* Painting and performance;
* Browsers can paint handles in their own layer.
*/
.noUi-base,
.noUi-handle {
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
/* Slider size and handle placement;
*/
.noUi-horizontal {
height: 18px;
}
.noUi-horizontal .noUi-handle {
width: 34px;
height: 28px;
left: -17px;
top: -6px;
}
.noUi-vertical {
width: 18px;
height: 400px;
}
.noUi-vertical .noUi-handle {
width: 28px;
height: 34px;
left: -6px;
top: -17px;
}
/* Styling;
*/
.noUi-target {
background: #FAFAFA;
border-radius: 4px;
border: 1px solid #D3D3D3;
box-shadow: inset 0 1px 1px #F0F0F0, 0 3px 6px -5px #BBB;
}
.noUi-connect {
background: #3FB8AF;
box-shadow: inset 0 0 3px rgba(51,51,51,0.45);
-webkit-transition: background 450ms;
transition: background 450ms;
}
/* Handles and cursors;
*/
.noUi-draggable {
cursor: w-resize;
}
.noUi-vertical .noUi-draggable {
cursor: n-resize;
}
.noUi-handle {
border: 1px...
JavaScript
9 // Use the conventional $ prefix for variables that hold jQuery objects.
var budgetSlider = document.getElementById('budget-slider');
// If the only purpose of the windowWidth() function is to set the slide variables,
// it can be renamed and rewritten to supply the full configuration object instead.
function buildSliderConfiguration() {
// When possible, you should cache calls to jQuery functions to improve performance.
var windowWidth = $(window).width();
var orientation;
if (windowWidth < 768) {
orientation = 'vertical';
}
else {
orientation = 'horizontal';
}
return orientation;
}
// This function can be called either to initialize the slider for the first time
// or to reload the slider when its size changes.
function configureSlider() {
var config = buildSliderConfiguration();
if (budgetSlider.noUiSlider) {
budgetSlider.noUiSlider.destroy();
console.log("destroy");
}
console.log(config)
noUiSlider.create(budgetSlider, {
start: [4, 6],
connect: true,
step: .5,
tooltips: [wNumb({ decimals: 0, prefix: '£', postfix: 'k' }), wNumb({ decimals: 0, prefix: '£', postfix: 'k' })],
margin: 1,
orientation: config,
range: {
'min': [1],
'max': [15]
}
}, true);
console.log("noUiSlider.create(budgetSlider,{start:[4,6],connect:!0,step:.5,tooltips:[wNumb({decimals:0,prefix:'£',postfix:'k'}),wNumb({decimals:0,prefix:'£',postfix:'k'})],margin:1," + config + ",range:{'min':[1],'max':[15]}},!0)")
}
// Configure the slider every time its size changes.
...