javascript - How to Toggle (or Scale) to reduce a DIV's vertical size (but only to 30% of initial height) -
so i've got div (a map) goes across width of page, i'd have button users can click "hide/unhide" div 3 things when clicked:
- scale vertical height of div 25% of original height...
- change div have opacity .3 faded when @ reduced height...
- revert normal height & opacity (1) when clicked again
here's i've got far: scales down correct vertical height
really appreciate help...
<!-- jquery stuff added in head--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <!-- code --> <div id="map"> map content here </div> <p class="hidemap">hide map</p> <script> $(document).ready(function() { $("p.hidemap").click(function () { $("#map").effect("scale", { percent: 25, direction: 'vertical' }, 500); }); }); </script>
try this:
var orig_height = $('#map').height(); $('.hidemap').click(function() { if($('#map').height() == orig_height) { var new_height = math.floor(orig_height * .25) + 'px'; var new_opacity = '.3'; } else { var new_height = orig_height + 'px'; var new_opacity = '1'; } $('#map').animate( { height: new_height, opacity: new_opacity },1000); }); working example: http://jsfiddle.net/x4nav/
Comments
Post a Comment