Lego2012
12/13/2016 - 3:45 PM

Equal Heights

Equal Heights

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

//* Enqueue scripts and styles
add_action( 'wp_enqueue_scripts', 'sk_set_equal_heights' );
function sk_set_equal_heights() {

  wp_enqueue_script( 'equal-heights',  get_stylesheet_directory_uri() . '/js/equal-heights.js', array( 'jquery' ), '', true );

}
jQuery(function( $ ){

  // equal heights
  function equalHeights() {
    var $col = $('.featured-content-all-recipes .entry'),
      maxHeight = [],
      rows = [],
      rowTop = 0,
      rowIndex = 0;
 
    $col.each(function() {
      $el = $(this);
      $el.css('height', '');
      if ($el.offset().top > rowTop) {
        rowIndex++;
        rows[rowIndex] = [];
        rowTop = $el.offset().top;
        maxHeight[rowIndex] = 0;
      }
      if ($el.height() > maxHeight[rowIndex]) {
        maxHeight[rowIndex] = $el.height();
      }
      rows[rowIndex].push($el);
    });
    for (row = 1; row <= rowIndex; row++) {
        for (i = 0; i <= rows[row].length; i++) {
          $(rows[row][i]).height(maxHeight[row]);
        }
      }
  }
  $(window).on('resize load', equalHeights);

});