Skip to content

Instantly share code, notes, and snippets.

@christabor
Created August 2, 2013 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christabor/6141749 to your computer and use it in GitHub Desktop.
Save christabor/6141749 to your computer and use it in GitHub Desktop.
Create a bunch of jquery sliders by mapping over an object of enumerable properties
// you can put your functions outside (my preference) or inside the object itself.
function foo() {
console.log('foo!');
}
function bar() {
console.log('bar!');
}
function bim() {
console.log('bim!');
}
var sliderMap = [
{id: '#foo-elem', min: 1, max: 100, range: 10, step: 2, fn: foo },
{id: '#bar-elem', min: 1, max: 1000, range: 20, step: 4, fn: bar },
{id: '#bim-elem', min: 1, max: 300, range: null, step: 1, fn: bim }
];
$(sliderMap).each(function(k, slider) {
var s = slider;
$(s.id).slider({
min: s.min,
max: s.max,
step: s.step,
slide: function(event, ui) {
// let's be responsible
if(s.fn !== null && s.fn) {
// call that sucker!
s.fn();
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment