Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Autor: Amin Fas
- Datum: 08.01.2020
- Beschreibung: JS Snippet > CodeGenius Homepage
- */
- (function($) {
- "use strict";
- //Navigation
- var app = function() {
- var body = undefined;
- var menu = undefined;
- var menuItems = undefined;
- var init = function init() {
- body = document.querySelector('body');
- menu = document.querySelector('.menu-icon');
- menuItems = document.querySelectorAll('.nav__list-item');
- applyListeners();
- };
- var applyListeners = function applyListeners() {
- menu.addEventListener('click', function() {
- return toggleClass(body, 'nav-active');
- });
- };
- var toggleClass = function toggleClass(element, stringClass) {
- if (element.classList.contains(stringClass)) element.classList.remove(stringClass);
- else element.classList.add(stringClass);
- };
- init();
- }();
- //Switch light/dark
- $("#switch").on('click', function() {
- if ($("body").hasClass("light")) {
- $("body").removeClass("light");
- $("#switch").removeClass("switched");
- } else {
- $("body").addClass("light");
- $("#switch").addClass("switched");
- }
- });
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement