Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.26 KB | None | 0 0
  1. (function($) {
  2.     $.fn.sameHeight = function() {
  3.         var selector = this;
  4.         var heights = [];
  5.  
  6.         // Save the heights of every element into an array
  7.         selector.each(function(){
  8.             var height = $(this).height();
  9.             heights.push(height);
  10.         });
  11.  
  12.         // Get the biggest height
  13.         var maxHeight = Math.max.apply(null, heights);
  14.         // Show in the console to verify
  15.         console.log(heights,maxHeight);
  16.  
  17.         // Set the maxHeight to every selected element
  18.         selector.each(function(){
  19.             $(this).height(maxHeight);
  20.         });
  21.     };
  22.    
  23.     $(document).ready(function() {
  24.         //use the.sameHeight()-Function for all elements, which shall have the same height, seperately
  25.         $('.product-grid-view .product-title a').sameHeight();
  26.         $('.owl-carousel .atw_item_title a').sameHeight();
  27.  
  28.         $(window).resize(function(){
  29.             // Do it when the window resizes too
  30.             $('.product-grid-view .product-title a').css('height', '');
  31.             $('.product-grid-view .product-title a').sameHeight();
  32.             $('.owl-carousel .atw_item_title a').css('height', '');
  33.             $('.owl-carousel .atw_item_title a').sameHeight();
  34.         });
  35.     });
  36.   })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement