Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. /*
  2. Autor: Amin Fas
  3. Datum: 08.01.2020
  4. Beschreibung: JS Snippet > CodeGenius Homepage
  5. */
  6.  
  7. (function($) {
  8. "use strict";
  9.  
  10. //Navigation
  11. var app = function() {
  12. var body = undefined;
  13. var menu = undefined;
  14. var menuItems = undefined;
  15. var init = function init() {
  16. body = document.querySelector('body');
  17. menu = document.querySelector('.menu-icon');
  18. menuItems = document.querySelectorAll('.nav__list-item');
  19. applyListeners();
  20. };
  21. var applyListeners = function applyListeners() {
  22. menu.addEventListener('click', function() {
  23. return toggleClass(body, 'nav-active');
  24. });
  25. };
  26. var toggleClass = function toggleClass(element, stringClass) {
  27. if (element.classList.contains(stringClass)) element.classList.remove(stringClass);
  28. else element.classList.add(stringClass);
  29. };
  30. init();
  31. }();
  32.  
  33.  
  34. //Switch light/dark
  35.  
  36. $("#switch").on('click', function() {
  37. if ($("body").hasClass("light")) {
  38. $("body").removeClass("light");
  39. $("#switch").removeClass("switched");
  40. } else {
  41. $("body").addClass("light");
  42. $("#switch").addClass("switched");
  43. }
  44. });
  45.  
  46. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement