dcba03b80412ea13b566e41910a99184d86cedb6.svn-base 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Auto Height for Layout - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Auto Height for Layout</h2>
  14. <p>This example shows how to auto adjust layout height after dynamically adding items.</p>
  15. <div style="margin:20px 0;">
  16. <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addItem()">Add Item</a>
  17. <a href="javascript:void(0)" class="easyui-linkbutton" onclick="removeItem()">Remove Item</a>
  18. </div>
  19. <div id="cc" style="width:700px;height:350px;">
  20. <div data-options="region:'north'" style="height:50px"></div>
  21. <div data-options="region:'south'" style="height:50px;"></div>
  22. <div data-options="region:'west'" style="width:150px;"></div>
  23. <div data-options="region:'center'" style="padding:20px">
  24. <p>Panel Content.</p>
  25. <p>Panel Content.</p>
  26. <p>Panel Content.</p>
  27. <p>Panel Content.</p>
  28. <p>Panel Content.</p>
  29. </div>
  30. </div>
  31. <script type="text/javascript">
  32. $(function(){
  33. $('#cc').layout();
  34. setHeight();
  35. });
  36. function addItem(){
  37. $('#cc').layout('panel','center').append('<p>More Panel Content.</p>');
  38. setHeight();
  39. }
  40. function removeItem(){
  41. $('#cc').layout('panel','center').find('p:last').remove();
  42. setHeight();
  43. }
  44. function setHeight(){
  45. var c = $('#cc');
  46. var p = c.layout('panel','center'); // get the center panel
  47. var oldHeight = p.panel('panel').outerHeight();
  48. p.panel('resize', {height:'auto'});
  49. var newHeight = p.panel('panel').outerHeight();
  50. c.height(c.height() + newHeight - oldHeight);
  51. c.layout('resize');
  52. }
  53. </script>
  54. </body>
  55. </html>