Advertisement
patrickc

Untitled

Nov 1st, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.         // DOM Ready
  3.         $(function() {
  4.        
  5.             var $el, $ps, $up, totalHeight;
  6.            
  7.             $(".sidebar-box .button").click(function() {
  8.                
  9.                 if (totalHeight == 0) {
  10.                        
  11.                 totalHeight = 0
  12.            
  13.                 $el = $(this);
  14.                 $p  = $el.parent();
  15.                 $up = $p.parent();
  16.                 $ps = $up.find("p:not('.read-more')");
  17.                
  18.                 // measure how tall inside should be by adding together heights of all inside paragraphs (except read-more paragraph)
  19.                 $ps.each(function() {
  20.                     totalHeight += $(this).outerHeight();
  21.                     // FAIL totalHeight += $(this).css("margin-bottom");
  22.                 });
  23.                            
  24.                 $up
  25.                     .css({
  26.                         // Set height to prevent instant jumpdown when max height is removed
  27.                         "height": $up.height(),
  28.                         "max-height": 9999
  29.                     })
  30.                     .animate({
  31.                         "height": totalHeight
  32.                     });
  33.                
  34.                 // fade out read-more
  35.                 // $p.fadeOut();
  36.                
  37.                 // prevent jump-down
  38.                 return false;
  39.                    
  40.             }
  41.             else {
  42.                 totalHeight = 0
  43.            
  44.                 $el = $(this);
  45.                 $p  = $el.parent();
  46.                 $up = $p.parent();
  47.                 $ps = $up.find("p:not('.read-more')");
  48.                
  49.                 // measure how tall inside should be by adding together heights of all inside paragraphs (except read-more paragraph)
  50.                 $ps.each(function() {
  51.                     totalHeight += $(this).outerHeight();
  52.                     // FAIL totalHeight += $(this).css("margin-bottom");
  53.                 });
  54.                            
  55.                 $up
  56.                     .css({
  57.                         // Set height to prevent instant jumpdown when max height is removed
  58.                         "height": $up.height(),
  59.                         "max-height": 120
  60.                     })
  61.                     .animate({
  62.                         "height": totalHeight
  63.                     });
  64.                
  65.                 // fade out read-more
  66.                 // $p.fadeOut();
  67.                
  68.                 // prevent jump-down
  69.                 return false;
  70.                 }
  71.             });
  72.         });
  73.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement