autoheight.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. <div class="demo-info">
  15. <div class="demo-tip icon-tip"></div>
  16. <div>This example shows how to auto adjust layout height after dynamically adding items.</div>
  17. </div>
  18. <div style="margin:10px 0;">
  19. <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addItem()">Add Item</a>
  20. <a href="javascript:void(0)" class="easyui-linkbutton" onclick="removeItem()">Remove Item</a>
  21. </div>
  22. <div id="cc" style="width:700px;height:350px;">
  23. <div data-options="region:'north'" style="height:50px"></div>
  24. <div data-options="region:'south'" style="height:50px;"></div>
  25. <div data-options="region:'west'" style="width:150px;"></div>
  26. <div data-options="region:'center'" style="padding:20px">
  27. <p>Panel Content.</p>
  28. <p>Panel Content.</p>
  29. <p>Panel Content.</p>
  30. <p>Panel Content.</p>
  31. <p>Panel Content.</p>
  32. </div>
  33. </div>
  34. <script type="text/javascript">
  35. $(function(){
  36. $('#cc').layout();
  37. setHeight();
  38. });
  39. function addItem(){
  40. $('#cc').layout('panel','center').append('<p>More Panel Content.</p>');
  41. setHeight();
  42. }
  43. function removeItem(){
  44. $('#cc').layout('panel','center').find('p:last').remove();
  45. setHeight();
  46. }
  47. function setHeight(){
  48. var c = $('#cc');
  49. var p = c.layout('panel','center'); // get the center panel
  50. var oldHeight = p.panel('panel').outerHeight();
  51. p.panel('resize', {height:'auto'});
  52. var newHeight = p.panel('panel').outerHeight();
  53. c.height(c.height() + newHeight - oldHeight);
  54. c.layout('resize');
  55. }
  56. </script>
  57. </body>
  58. </html>