Last active
August 28, 2020 07:43
-
-
Save leongersen/7560025 to your computer and use it in GitHub Desktop.
A small handler to initialize noUiSlider with inline attributes. Implementation is roughly inspired by, but not fully compatible to, the specification for input[type="range"]. Attributes with or without the 'data-' prefix will be handled.
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
(function(){ | |
'use strict'; | |
$('[data-slider]').each(function(){ | |
function d(a,b){ | |
return parseFloat(a.attr(b) || a.attr('data-'+b)); | |
} | |
var | |
min = d($(this),'min') | |
,max = d($(this),'max') | |
,step = d($(this),'step') | |
,value = d($(this),'value') | |
,range = !isNaN(min) && !isNaN(max) ? { 'min': min, 'max': max } : { 'min': 0, 'max': 100 } | |
,start = !isNaN(value) ? value : ( range[1] - range[0] ) / 2 | |
,settings = { | |
range: range | |
,step: !isNaN(step) ? step : 1 | |
,start: start | |
,serialization: { | |
resolution: 1 | |
} | |
}; | |
$(this).noUiSlider(settings); | |
}); | |
}()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@renduh, This gist uses jQuery (and an older noUiSlider version), but it could easily be rewritten without it. The html would look something like the following: