Guest User

Untitled

a guest
Mar 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. $(document).ready(function(){
  2. ("#btnSelection").click(btnSelectionAction);
  3. anchorListenerforfloatDiv();
  4. }
  5. function btnSelectionAction(){
  6. var value = $("#btnSelection").attr("value");
  7. // check which content we are showing
  8. if( value == "see personal projects"){
  9. removeTitleandAnchor();// remove title and anchor
  10. // set text of button
  11. $("#btnSelection").attr("value","see portfolio");
  12. floatDivPersonalProjects()// add anchor
  13. }else if(value == "see portfolio"){
  14. removeTitleandAnchor();// remove title and anchor
  15. // set text of button
  16. $("#btnSelection").attr("value","see personal projects");
  17. floatDivPortfolio();// add anchor
  18. }
  19. }
  20. // remove title and anchor
  21. function removeTitleandAnchor(){
  22. $( "#title h2" ).remove();
  23. $( "#title p" ).remove();
  24. $( "#links_to_conten a" ).remove();
  25. $( "#links_to_conten br" ).remove();
  26. }
  27.  
  28.  
  29. function floatDivPersonalProjects(){
  30. // adding title and introduction of what your seeing
  31. $("#title").append("<h2>Personal Projects</h2><p>This part a will show the personal projects i done outside of college</p>");
  32. $("#links_to_conten").append("<br>"); // add break to aside
  33. // create anchor from h2
  34. $("article h2").each(function( index ) {
  35. $("#links_to_conten").append("<a>"+ $(this).text()+"</a>")
  36. });
  37.  
  38. // insert break after each anchor
  39. $( "#links_to_conten a" ).each(function() {
  40. $("<br>").insertAfter( this )
  41. });
  42.  
  43.  
  44.  
  45. $("#links_to_conten").append("<a>Back to top</a>"); // add anchor to aside
  46. // adding href so when you click on link it will take you to the article
  47. $("#links_to_conten a").each(function( index ) {
  48. var num = index + 1;
  49. $(this).attr("href","#heading" + num);
  50.  
  51. if(index == 4){
  52. $(this).attr("href","#heading" +1);
  53. }
  54. });
  55. }
  56.  
  57. function floatDivPortfolio(){
  58. // adding title and introduction of what your seeing
  59. $("#title").append("<h2>Portfolio</h2><p>The purpose of my portfolio is to summarize my" +
  60. "programming knowledge, also show some of my college projects</p>");
  61. $("#links_to_conten").append("<br>"); // add break to aside
  62. // create anchor from h2
  63. $("article h2").each(function( index ) {
  64. $("#links_to_conten").append("<a>"+ $(this).text()+"</a>")
  65. });
  66.  
  67. // insert break after each anchor
  68. $( "#links_to_conten a" ).each(function() {
  69. $("<br>").insertAfter( this )
  70. });
  71.  
  72.  
  73.  
  74. $("#links_to_conten").append("<a>Back to top</a>"); // add anchor to aside
  75. // adding href so when you click on link it will take you to the article
  76. $("#links_to_conten a").each(function( index ) {
  77. var num = index + 1;
  78. $(this).attr("href","#heading" + num);
  79.  
  80. if(index == 4){
  81. $(this).attr("href","#heading" +1);
  82. }
  83. });
  84. }
  85. // listerner for anchor in div
  86. function anchorListenerforfloatDiv(){
  87. $("#links_to_conten a").click (function(index) {
  88. if(index != 3 ){
  89.  
  90. // get the id selector of the selected h2 element from the <a> tag
  91. var id = $(this).attr("href");
  92.  
  93. // setting all the heading back to normal except the current want
  94. for(var i = 1; i < 5 ;++i){
  95.  
  96. $("#heading" + i ).not(this).css({ "color": "black", "font-size": "120%" });
  97.  
  98. }
  99.  
  100. // change the styles for the selected heading
  101. $(id).css({ "color": "#f794f2", "font-size": "150%" });
  102. }
  103.  
  104. });
  105. }
Add Comment
Please, Sign In to add comment