I have several divs which change their size by clicking on different radio buttons. If you click on a radio button with a small window size, the div shrinks. After that, if you resize the window (make it bigger) and click on another radio button to make the div grow again it does not grow to 100% percent of the original size. What is the problem? I already use percentages in the CSS:
#kunstmuseum {
left: 0;
top: 0;
height: 80px;
width: 11.5%;
background-color:#334D5C;
white-space: normal;
display: inline-block;
border-top: 0;
}
Here is the HTML for the radio buttons:
<input id="kunst_radio1" type="radio" name="kunstmuseum" value="0" checked="checked" onClick="animateDiv('kunstmuseum', 'nichts')">
<input id="kunst_radio2" type="radio" name="kunstmuseum" value="6794200" onClick="animateDiv('kunstmuseum', 'halb')">
<input id="kunst_radio3" type="radio" name="kunstmuseum" value="13588400" onClick="animateDiv('kunstmuseum', 'voll')">
Here is the HTML for the div to be animated:
<div id="kunstmuseum"></div>
Here is the JS-code:
var mapping = {
kunstmuseum: {
voll: 0,
halb: 0.5,
nichts: 1
}
};
function animateDiv(type, val) {
var div = $('#' + type);
if(div.data('originalWidth') == undefined)
div.data('originalWidth', div.width());
var width = div.data('originalWidth');
width *= mapping[type][val];
$('#' + type).animate({width: width}, 500);
}
And here is a fiddle which is unfortunately not working: http://jsfiddle.net/zord/r1zut4we/
But the animate function works on my website: http://labs.tageswoche.ch/budget/budget.html