Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function getWindowWidth2() {
  2. return window.innerWidth || document.body.clientWidth;
  3. }
  4.  
  5. $(window).resize(function(){
  6. myMatchHeight('.sameHeight1'); // first group of things I want the same height
  7. myMatchHeight('.sameHeight2'); // second group of things I want the same height
  8. });
  9. $(window).load(function(){
  10. myMatchHeight('.sameHeight1');
  11. myMatchHeight('.sameHeight2');
  12. });
  13.  
  14. function myMatchHeight(x){
  15. var w = getWindowWidth2(); // more accurate than $(window).width();
  16. //console.log('current width: ' + w);
  17. if (w >= 768){ // no need to resize if stacking on mobile
  18. var h = 0;
  19. $(x).each(function(){ // loop through each element with this class
  20. $(this).css({'height':'auto'}); // reset so it's not based on your adjusted height
  21. if($(this).outerHeight() > h){ // check to see if we have a new height champion
  22. h = $(this).outerHeight();
  23. }
  24. });
  25. $(x).css({'height':h}); // set all the guys with this class to the height of the tallest
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement