Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. HTML:
  2. <div class="tabs_wrapper">
  3. <ul>
  4. <li class="tab_menu_item">tab1</li>
  5. <li class="tab_menu_item">tab2</li>
  6. <li class="tab_menu_item">tab3</li>
  7. </ul>
  8. <div>
  9. <div class="tab_content_item">
  10. <h1>tab1</h1>
  11. <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Esse, aspernatur?</p>
  12. </div>
  13. <div class="tab_content_item">
  14. <h1>tab2</h1>
  15. <p>Lorem ipsum dolor sit amet, </p>
  16. </div>
  17. <div class="tab_content_item">
  18. <h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Omnis consequuntur incidunt laudantium inventore aperiam sint molestiae, quodi dolorem repellendus asperiores sit facere au?</p>
  19. </div>
  20. </div>
  21. </div>
  22.  
  23. SCSS:
  24. .tabs_wrapper {
  25. max-width: 500px;
  26. margin: 0 auto;
  27. border:1px solid red;
  28. >ul {
  29. display: block;
  30. padding: 10px 0px 0px 0px;
  31. li.tab_menu_item {
  32. padding: 5px 10px;
  33. background-color: #D8D8D8;
  34. }
  35. &:after {
  36. content: '';
  37. display: table;
  38. clear:both;
  39. }
  40. }
  41. .tab_content_item {
  42. background-color: #D8D8D8;
  43. }
  44. }
  45.  
  46. JS:
  47. $(document).ready(function(){
  48.  
  49. //equal Height for tabs content
  50. var maxHeight = 0;
  51. $(".tab_content_item").each(function(){
  52. if ( $(this).height() > maxHeight ) {
  53. maxHeight = $(this).height();
  54. }
  55. });
  56. $(".tab_content_item").height(maxHeight);
  57.  
  58.  
  59. //boot styles
  60. $('.tab_menu_item').each(function(i) {
  61. $(this).css({"display":"block","float":"left"});
  62. if (i==0) {
  63. $(this).css("opacity","1");
  64. }
  65. else {
  66. $(this).css("opacity","0.3");
  67. }
  68. });
  69. $('.tab_content_item').each(function(i) {
  70. if (i==0) {
  71. $(this).show();
  72. }
  73. else {
  74. $(this).hide();
  75. }
  76. });
  77.  
  78.  
  79. // click styles
  80. $('.tab_menu_item').click(function(i) {
  81. var index_selected = $(this).index();
  82. $('.tab_menu_item').each(function(i) {
  83. if (i==index_selected) {
  84. $(this).css("opacity","1");
  85. $('.tab_content_item').eq(i).show();
  86. }
  87. else {
  88. $(this).css("opacity","0.3");
  89. $('.tab_content_item').eq(i).hide();
  90. }
  91. });
  92. });
  93. }); // end /Ready
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement