Created
August 2, 2013 17:35
-
-
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
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
// 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