Skip to content

Instantly share code, notes, and snippets.

@dudleystorey
Created April 27, 2014 07:17
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dudleystorey/11339485 to your computer and use it in GitHub Desktop.
Creates an auto-generated series of option values to generate ticks for Chrome & IE10 range sliders. slider requires min,max,step and list attributes.
function ticks(element) {
if (element.hasOwnProperty('list') && element.hasOwnProperty('min') && element.hasOwnProperty('max') && element.hasOwnProperty('step')) {
var datalist = document.createElement('datalist'),
minimum = parseInt(element.getAttribute('min')),
step = parseInt(element.getAttribute('step')),
maximum = parseInt(element.getAttribute('max'));
datalist.id = element.getAttribute('list');
for (var i = minimum; i < maximum+step; i = i + step) {
datalist.innerHTML +="<option value="+i+"></option>";
}
element.parentNode.insertBefore(datalist, element.nextSibling);
}
}
var lists = document.querySelectorAll("input[type=range][list]"),
arr = Array.prototype.slice.call(lists);
arr.forEach(ticks);
@jawu
Copy link

jawu commented Feb 24, 2015

Thanks for that!
I'm using some of your code here: https://github.com/jawu/rangerer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment