autoheight.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.layout('resize',{
  51. height: (c.height() + newHeight - oldHeight)
  52. });
  53. }
  54. </script>
  55. </body>
  56. </html>