Created
April 27, 2014 07:17
-
-
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.
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 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for that!
I'm using some of your code here: https://github.com/jawu/rangerer