-
Notifications
You must be signed in to change notification settings - Fork 36
/
script.js
36 lines (30 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
const searchForm = document.querySelector('.search-form');
const searchBtn = document.querySelector('#search-btn');
const cartItem = document.querySelector('.cart-items-container')
const cartBtn = document.querySelector('#cart-btn')
const navbar = document.querySelector('.navbar')
const menuBtn = document.querySelector('#menu-btn')
searchBtn.addEventListener('click', ()=>{
searchForm.classList.toggle('active');
document.addEventListener('click', (e)=>{
if(!e.composedPath().includes(searchBtn) && !e.composedPath().includes(searchForm) ){
searchForm.classList.remove('active');
}
})
})
cartBtn.addEventListener('click', ()=>{
cartItem.classList.toggle('active');
document.addEventListener('click', (e)=>{
if(!e.composedPath().includes(cartBtn) && !e.composedPath().includes(cartItem) ){
cartItem.classList.remove('active');
}
})
})
menuBtn.addEventListener('click', ()=>{
navbar.classList.toggle('active');
document.addEventListener('click', (e)=>{
if(!e.composedPath().includes(navbar) && !e.composedPath().includes(menuBtn) ){
navbar.classList.remove('active');
}
})
})