Guest User

Untitled

a guest
Jun 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <div id="boxes">
  2. <div id="boxone">
  3. <p>...</p>
  4. </div>
  5. <div id="boxtwo">
  6. <p>...</p>
  7. </div>
  8. <div id="boxthree">
  9. <p>...</p>
  10. </div>
  11. <div id="boxfour">
  12. <p>...</p>
  13. </div>
  14. </div>
  15.  
  16. div#boxes {
  17. width: 100%;
  18. }
  19.  
  20. div#boxes div {
  21. width: 49.9%;
  22. float: left;
  23. }
  24.  
  25. $(function() {
  26. var maxHeight = 0;
  27. $('div#boxes div').each(function(){
  28. if (maxHeight < $(this).height()) {maxHeight = $(this).height()}
  29. });
  30. $('div#boxes div').each(function(){
  31. $(this).height(maxHeight);
  32. });
  33. });
  34.  
  35. function sortNumber(a,b) {
  36. return a - b;
  37. }
  38.  
  39. function maxHeight() {
  40. var heights = new Array();
  41. $('div#boxes div').each(function(){
  42. $(this).css('height', 'auto');
  43. heights.push($(this).height());
  44. heights = heights.sort(sortNumber).reverse();
  45. $(this).css('height', heights[0]);
  46. });
  47. }
  48.  
  49. $(document).ready(function() {
  50. maxHeight();
  51. })
  52.  
  53. $(window).resize(maxHeight);
  54.  
  55. // global variables
  56.  
  57. doAdjust = true;
  58. previousWidth = 0;
  59.  
  60. // raise doAdjust flag every time the window width changes
  61.  
  62. $(window).resize(function() {
  63. var currentWidth = $(window).width();
  64. if (previousWidth != currentWidth) {
  65. doAdjust = true;
  66. }
  67. previousWidth = currentWidth;
  68. })
  69.  
  70. // every half second
  71.  
  72. $(function() {
  73. setInterval('maybeAdjust()', 500);
  74. });
  75.  
  76. // check the doAdjust flag
  77.  
  78. function maybeAdjust() {
  79. if (doAdjust) {
  80. adjustBoxHeights();
  81. doAdjust = false;
  82. }
  83. }
  84.  
  85. // loop through the DIVs and find the height of the tallest one
  86. // then loop again and set them all to that height
  87.  
  88. function adjustBoxHeights() {
  89. var maxHeight = 0;
  90. $('div#boxes div').each(function(){
  91. $(this).height('auto');
  92. if (maxHeight < $(this).height()) {maxHeight = $(this).height()}
  93. });
  94. $('div#boxes div').each(function(){
  95. $(this).height(maxHeight);
  96. });
  97. }
Add Comment
Please, Sign In to add comment