-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
113 lines (95 loc) · 3.07 KB
/
app.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const projects = [
{
name: "project one",
tags: "#javascript, #fullstack, #ui/ux, #backend",
image: "https://picsum.photos/200?grayscale&random=1",
},
{
name: "project two",
tags: "#javascript, #fullstack",
image: "https://picsum.photos/200?random=2&grayscale",
},
{
name: "project two",
tags: "#javascript, #fullstack",
image: "https://picsum.photos/200?random=3&grayscale",
},
{
name: "project two",
tags: "#javascript, #fullstack",
image: "https://picsum.photos/200?random=4&grayscale",
},
{
name: "project two",
tags: "#javascript, #fullstack",
image: "https://picsum.photos/200?random=5&grayscale",
},
];
const links = document.querySelectorAll(".link");
links.forEach((link) => {
link.addEventListener("click", () => {
links.forEach((ele) => ele.classList.remove("active"));
link.classList.add("active");
});
});
// creating dynamic project card
const projectContainer = document.querySelector('.project-container');
projects.forEach(project => {
projectContainer.innerHTML += `
<div class="project-card" data-tags="#all, ${project.tags}">
<img src="${project.image}" alt="">
<div class="content">
<h1 class="project-name">${project.name}</h1>
<span class="tags">${project.tags}</span>
</div>
</div>
`;
})
// filters
const filters = document.querySelectorAll('.filter-btn');
filters.forEach(filterBtn => {
filterBtn.addEventListener('click', () => {
let id = filterBtn.getAttribute('id');
let projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
if(card.getAttribute('data-tags').includes(id)){
card.classList.remove('hide');
} else{
card.classList.add('hide');
}
})
filters.forEach(btn => btn.classList.remove('active'));
filterBtn.classList.add('active');
})
})
//contact form
const contactBtn = document.querySelector('.contact-btn');
const firstName = document.querySelector('.first-name');
const lastName = document.querySelector('.last-name');
const email = document.querySelector('.email');
const msg = document.querySelector('.message');
contactBtn.addEventListener('click', () => {
if(firstName.value.length && lastName.value.length && email.value.length && msg.value.length){
fetch('/mail', {
method: 'post',
headers: new Headers({'Content-Type': 'application/json'}),
body: JSON.stringify({
firstName: firstName.value,
lastName: lastName.value,
email: email.value,
msg: msg.value,
})
})
.then(res => res.json())
.then(data => {
alert(data);
})
}
})
//toggle button
const toggleBtn = document.querySelector('.toggle-btn');
const linkContainer = document.querySelector('.links-container');
toggleBtn.addEventListener('click', () => {
toggleBtn.classList.toggle('active');
linkContainer.classList.toggle('show');
})