-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (31 loc) · 1.17 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Toggle Menu
const toggleMenu = document.querySelector('#toggle-menu');
const toggleMenuIcon = toggleMenu.querySelector('img');
const menu = document.querySelector('#menu');
toggleMenu.addEventListener('click',()=>{
menu.classList.toggle('translate-y-[-200%]');
changeMenuIcon();
})
//close menu when click Menu list
const navlinks = document.querySelectorAll('.nav-link');
navlinks.forEach(navlink =>{
navlink.addEventListener('click',()=>{
menu.classList.add('translate-y-[-200%]');
changeMenuIcon();
})
})
function changeMenuIcon(){
const isContainTranslate = menu.classList.contains('translate-y-[-200%]');
const icon = isContainTranslate ? 'icon-menu':'icon-close';
toggleMenuIcon.src = `./images/icons/${icon}.svg`;
}
// Toggle Theme
const html = document.querySelector('html');
const toggleTheme = document.querySelector('#toggle-theme');
const toggleThemeIcon = toggleTheme.querySelector('img');
toggleTheme.addEventListener('click',()=>{
html.classList.toggle('dark');
const isDark = html.classList.contains('dark');
const themeIcon = isDark ? 'light' : 'dark';
toggleThemeIcon.src = `./images/icons/icon-${themeIcon}.svg`;
})