samedi 29 novembre 2014

make a for-loop of several js functions


i have several js functions doing the same thing width different values for different divs. Here is the HTML-code:



<input id="kunst_radio1" type="radio" name="kunstmuseum" value="0" checked="checked" onClick="animateKunst('null')"><label for="kunst_radio1"></label>
<input id="kunst_radio2" type="radio" name="kunstmuseum" value="6794200" onClick="animateKunst('halb')"><label for="kunst_radio2"></label>
<input id="kunst_radio3" type="radio" name="kunstmuseum" value="13588400" onClick="animateKunst('voll')"><label for="kunst_radio3"></label>
<input id="hist_radio1" type="radio" name="hist" checked="checked" onClick="animateHist('null')"><label for="hist_radio1"></label>
<input id="hist_radio2" type="radio" name="hist" onClick="animateHist('halb')"><label for="hist_radio2"></label>
<input id="hist_radio3" type="radio" name="hist" onClick="animateHist('voll')"><label for="hist_radio3"></label>


I have about 15 radio button groups and for each group I have to execute this function with different values:



function animateKunst(val) {
var div = $('#kunstmuseum');
if(div.data('originalWidth') == undefined)
div.data('originalWidth', div.width());

var width = div.data('originalWidth');

if (val=="voll")
width *= .6;
else if (val=="halb")
width *= .8;

$('#kunstmuseum').animate({width: width}, 500);
}
function animateHist(val) {
var div = $('#historisch');
if(div.data('originalWidth') == undefined)
div.data('originalWidth', div.width());

var width = div.data('originalWidth');

if (val=="voll")
width *= .7;
else if (val=="halb")
width *= .9;

$('#historisch').animate({width: width}, 500);
}


Can I put all the values in an array and then make a for-loop? How can I do that?





Aucun commentaire:

Enregistrer un commentaire