Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. $(function() {
  2. $('#category-1-button a').bind('click', function() {
  3. $(this).css({opacity:'1'});
  4. $('#category-2-button a,#category-3-button a').css({opacity:'0.4'});
  5. $('#blog-headers').css({backgroundPosition: '0 0'});
  6. $('#category_2,#category_3').hide(0, function() {
  7. $('#category_1').show(0);
  8. });
  9. });
  10. });
  11.  
  12. $(function() {
  13. $('#category-2-button a').bind('click', function() {
  14. $(this).css({opacity:'1'});
  15. $('#category-1-button a,#category-3-button a').css({opacity:'0.4'});
  16. $('#blog-headers').css({backgroundPosition: '0 -144px'});
  17. $('#category_1,#category_3').hide(0, function() {
  18. $('#category_2').show(0);
  19. });
  20. });
  21. });
  22.  
  23. $(function() {
  24. $('#category-3-button a').bind('click', function() {
  25. $(this).css({opacity:'1'});
  26. $('#category-1-button a,#category-2-button a').css({opacity:'0.4'});
  27. $('#blog-headers').css({backgroundPosition: '0 -288px'});
  28. $('#category_1,#category_2').hide(0, function() {
  29. $('#category_3').show(0);
  30. });
  31. });
  32. });
  33.  
  34. $(function() {
  35. $('#category-1-button a, #category-2-button a, #category-3-button a').click(function () {
  36. $('#category-1-button a,#category-2-button a,#category-3-button a').not(this).css({opacity:'0.4'});
  37. $(this).css({opacity:'1'});
  38. var myParent = $(this).parent();
  39. if (myParent == $('#category-1-button')) {
  40. $('#blog-headers').css({backgroundPosition: '0 0'});
  41. $('#category_3,#category_2').hide(0, function() {
  42. $('#category_1').show(0);
  43. });
  44. } else if (myParent == $('#category-2-button')) {
  45. $('#blog-headers').css({backgroundPosition: '0 -144px'});
  46. $('#category_1,#category_3').hide(0, function() {
  47. $('#category_2').show(0);
  48. });
  49. } else if (myParent == $('#category-3-button')) {
  50. $('#blog-headers').css({backgroundPosition: '0 -288px'});
  51. $('#category_1,#category_2').hide(0, function() {
  52. $('#category_3').show(0);
  53. });
  54. }
  55. });
  56. }
  57.  
  58. $(function() {
  59. var categories = $('[id^="category_"]');
  60. var category_buttons_a = $('.category_button a').each(function( idx ) {
  61. $(this).bind('click', function() {
  62. $(this).css({opacity:'1'});
  63. category_buttons_a.not(this).css({opacity:'0.4'});
  64. $('#blog-headers').css({backgroundPosition: '0 ' + (idx * -144) + 'px'});
  65. categories.hide().filter( '#category_' + (idx + 1) ).show();
  66. });
  67. });
  68. });
  69.  
  70. (function($){
  71. "use strict";
  72. var $categoryButtonLinks;
  73.  
  74. $categoryButtonLinks = $('#category-1-button a, #category-2-button a, #category-3-button a').click(clickCategoryButtonLink);
  75.  
  76. $categories = $('#category_1, #category_2, #category_3');
  77.  
  78. function clickCategoryButtonLink(e)
  79. {
  80. var $this, $category, index, offset;
  81. $this = $(this).css('opacity', '1');
  82. index = $categoryButtonLinks.index($this);
  83. offset = -144 * index;
  84. index += 1;
  85. $category = $('#category_'+index);
  86. $categoryButtonLinks.not($this).css('opacity', '0.4');
  87. $('#blog-headers').css('background-position', '0 ' + offset + 'px' );
  88. $categories.not($category).hide(0, function(){
  89. $category.show(0);
  90. });
  91. }
  92.  
  93. })(jQuery);
  94.  
  95. <div id="class="category-1-button" class="category_button">
  96. <a href="#Category_1">Category 1</a>
  97. </div>
  98.  
  99. .category_button a {
  100. opacity: 0.4;
  101. }
  102.  
  103. .category {
  104. display: none;
  105. }
  106.  
  107. /* The following rules/selectors could/should be generated by a script */
  108. .category_1_selected #category-1-button a,
  109. .category_2_selected #category-2-button a,
  110. .category_3_selected #category-3-button a {
  111. opacity: 1;
  112. }
  113.  
  114. .category_1_selected #category_1,
  115. .category_2_selected #category_2,
  116. .category_3_selected #category_3 {
  117. display: block;
  118. }
  119.  
  120. .category_1_selected #blog-headers {
  121. background-position: 0 0;
  122. }
  123.  
  124. .category_2_selected #blog-headers {
  125. background-position: 0 -144px;
  126. }
  127.  
  128. .category_3_selected #blog-headers {
  129. background-position: 0 -288px;
  130. }
  131.  
  132. $(function() {
  133. var category_buttons_a = $('.category_button a').click(function() {
  134. // I'm putting the class on the body as an example, but any other element the
  135. // surrounds the buttons, categorys and the blog header is fine.
  136. $("body").removeClass().addClass(this.href.slice(1) + "_selected");
  137. });
  138. });
  139.  
  140. <div>
  141. <a href="#Category_1" id="class="category-1-button" class="category_button">Category 1</a>
  142. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement