BossArturKA

Untitled

Jun 7th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.74 KB | None | 0 0
  1. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  2.  
  3. <style>
  4.     .content {
  5.     overflow: hidden;}
  6. </style>
  7.  
  8. <div>
  9.     <div class="content">
  10.         <p>Контент.</p>
  11.     </div>
  12.     <button class="show-hide">Показать</button>
  13. </div>
  14.  
  15. <script>
  16.     var halfText = $('.content').innerHeight() / 4,
  17.     textHeight = $('.content').innerHeight();
  18.     $('.content').css('height', $('.content').innerHeight() / 4);
  19.     $('.show-hide').click(function() {
  20.     if( $('.content').innerHeight() == halfText ) {
  21.     $('.content').animate({ height: textHeight }, 500);
  22.     $(this).text('Скрыть');
  23.     } else {
  24.     $('.content').animate({ height: halfText }, 500);
  25.     $(this).text('Показать');
  26.     }
  27.     });
  28. </script>
Advertisement
Add Comment
Please, Sign In to add comment