1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function() { $("#btn1").click(function(){ $("#box").animate({height:"300px"}); }); $("#btn2").click(function(){ $("#box").animate({height:"100px"}); }); }); </script> </head> <body> <button id="btn1">Animate height</button> <button id="btn2">Reset height</button> <div id="box" style="background:#98bf21;height:100px;width:100px;margin:6px;"> </div> </body> </html> |
And another good example of hiding divs with a button. Many ways to adjust this code….
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<script type="text/javascript"> $(document).ready(function(){ $(".slidingDiv").show(); $(".show_hide").show(); $('.show_hide').click(function() { if($(".slidingDiv2").css("width") == "95%") { $(".slidingDiv").show(); $('.slidingDiv2').animate({"width": '40%'}); } else { $(".slidingDiv").hide(); $('.slidingDiv2').animate({"width": '95%'}); } }); }); </script> |