Guest User

Untitled

a guest
Jul 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. // put all code in document ready function
  2. // to prevent it from loading before DOM is loaded
  3. $(document).ready(function(){
  4. // check if script is linked properly:
  5. // alert("Document is ready!");
  6.  
  7. $("textarea").css("color", "yellow");
  8. $("textarea").css("background-color", "blue");
  9.  
  10. // Tooltips
  11. $(function () {
  12. $('#item1').tooltip();
  13. });
  14.  
  15. $(function () {
  16. $('[data-toggle="tooltip"]').tooltip();
  17. });
  18.  
  19. // Smooth scrolling
  20. var $root = $('html, body');
  21. $('#navbar-example a').click(function() {
  22. var href = $.attr(this, 'href');
  23. if (href != undefined && href != '#') {
  24. $root.animate({
  25. scrollTop: $(href).offset().top
  26. }, 500, function () {
  27. window.location.hash = href;
  28. });
  29. }
  30. return false;
  31. });
  32.  
  33. // Event listeners contact submit button
  34.  
  35. // Exercise 2.8: Conditional statements
  36. // Turn message-box red when trying to submit empty string
  37. $("button").on('click', function() {
  38. if ($('.message-box').val() === "") {
  39. $(".message-box").css("border", "2px solid red");
  40. } else {
  41. var comment = $('.message-box').val();
  42. $('#visible-comment').html(comment);
  43. console.log(comment);
  44. $('.message-box').hide();
  45. }
  46. });
  47.  
  48. // Hide name and e-mail form after submission
  49. // Write user input to DOM
  50. $('#button').on('click', function() {
  51.  
  52. // store user input in variables
  53. var name = $('#yourName').val();
  54. var email = $('#yourEmail').val();
  55.  
  56. // output user input to console
  57. console.log(name);
  58. console.log(email);
  59.  
  60.  
  61. // append user input to DOM
  62. $('#visible-name').html(name);
  63. $('#visible-email').html(email);
  64.  
  65. // hide contact form
  66. $('#yourName').hide();
  67. $('#yourEmail').hide();
  68.  
  69. return false;
  70. });
  71.  
  72. // Count message length and write to DOM
  73. $(".message-box").on("keyup", function() {
  74. console.log("keyup happened");
  75.  
  76. var charCount = $(".message-box").val().length;
  77. console.log(charCount);
  78. $("#char-count").html("you typed " + charCount + " chars.");
  79.  
  80. if(charCount > 50) {
  81. $("#char-count").css("color", "red");
  82. } else {
  83. $("#char-count").css("color", "black");
  84.  
  85. };
  86.  
  87. // Experiments: changes BG color to green when start typing,
  88. // change BG color to yellow when typing 42
  89. if ($('.message-box').val() == 42) {
  90. console.log("Input is 42, which turns the background yellow")
  91. $('body').css("background-color", "yellow");
  92.  
  93. } else{
  94. $('body').css("background-color", "green");
  95.  
  96. };
  97. });
  98.  
  99. // Work section
  100.  
  101. // Display portfolio items from arrays stored in work.js
  102.  
  103. // Test if work.js is properly linked
  104. console.log(pfPhotos);
  105.  
  106. // Generate and append HTML to portfolio section
  107. //Uses data (headings, photos, descriptions) from work.js
  108. for (var i = 0; i < pfPhotos.length; i++) {
  109. console.log(i);
  110. $("#work").append('\
  111. <div class="col-sm-12 col-md-4 col-lg-4">\
  112. <div class="col-sm-12 col-md-12 col-lg-12 portfolio-col">\
  113. <h4>' + pfHeadings[i] + '</h4>\
  114. <img class="img-fluid element-shadow" src="' + pfPhotos[i] + '">\
  115. </div>\
  116. <div class="col-sm-12 col-md-12 col-lg-12 portfolio-col">\
  117. <p>\
  118. '+ pfDescriptions[i] +
  119. '</p>\
  120. </div>\
  121. </div>');
  122.  
  123. // Add colored border to each images
  124. var images = $("#work img");
  125. if(i%2 === 0){
  126. $(images[i]).css("border", "2px solid DodgerBlue");
  127. } else {
  128. $(images[i]).css("border", "2px solid salmon");
  129. };
  130. };
  131.  
  132. });
Add Comment
Please, Sign In to add comment