-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
152 lines (126 loc) · 5.18 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Get the navbar element
const navbar = document.querySelector('.navbar');
// Get the initial offset of the navbar
const navbarOffset = navbar.offsetTop;
// Function to fix the navbar's position when scrolling
function fixNavbar() {
if (window.pageYOffset >= navbarOffset) {
navbar.classList.add('fixed');
} else {
navbar.classList.remove('fixed');
}
}
// Add event listener for scroll event
window.addEventListener('scroll', fixNavbar);
// script.js
window.onload = function() {
const img = document.querySelector('.app__header-img');
let opacity = 0;
const animationSpeed = 0.02; // Adjust animation speed as needed
// Function to fade in the image
function fadeInImage() {
opacity += animationSpeed;
img.style.opacity = opacity;
if (opacity < 1) {
requestAnimationFrame(fadeInImage);
}
}
// Start the fade-in animation
requestAnimationFrame(fadeInImage);
};
document.addEventListener('DOMContentLoaded', function() {
const filterItems = document.querySelectorAll('.app__work-filter-item');
const projects = document.querySelectorAll('.project');
// Function to filter projects
function filterProjects(filter) {
projects.forEach(project => {
if (filter === 'all' || project.dataset.category === filter) {
project.style.display = 'block';
} else {
project.style.display = 'none';
}
});
}
// Add click event listeners to filter items
filterItems.forEach(item => {
item.addEventListener('click', function() {
// Remove 'item-active' class from all filter items
filterItems.forEach(filterItem => filterItem.classList.remove('item-active'));
// Add 'item-active' class to the clicked filter item
item.classList.add('item-active');
// Get the filter category from the clicked filter item
const filter = item.getAttribute('data-filter');
// Filter projects based on the selected filter
filterProjects(filter);
});
});
// Display all projects by default
filterProjects('all');
});
window.onload = function() {
const img = document.querySelector('.app__work-portfolio');
let opacity = 0;
const animationSpeed = 0.018; // Adjust animation speed as needed
// Function to fade in the image
function fadeInImage() {
opacity += animationSpeed;
img.style.opacity = opacity;
if (opacity < 1) {
requestAnimationFrame(fadeInImage);
}
}
// Start the fade-in animation
requestAnimationFrame(fadeInImage);
};
window.addEventListener('DOMContentLoaded', function() {
const navbar = document.querySelector('.app__navbar');
const blurryBackground = document.querySelector('.blurry-background');
window.addEventListener('scroll', function() {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
blurryBackground.classList.add('active');
} else {
navbar.classList.remove('scrolled');
blurryBackground.classList.remove('active');
}
});
});
document.addEventListener('DOMContentLoaded', function() {
const sendButton = document.getElementById('send-button');
sendButton.addEventListener('click', function() {
const username = document.getElementById('username').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
if (username && email && message) {
// Log the form data to the console
console.log('Name:', username);
console.log('Email:', email);
console.log('Message:', message);
// Store the form data in localStorage
let messages = JSON.parse(localStorage.getItem('messages')) || [];
messages.push({ username, email, message });
localStorage.setItem('messages', JSON.stringify(messages));
// Display a confirmation message to the user
const confirmationMessage = document.getElementById('confirmation-message');
confirmationMessage.style.display = 'block';
// Clear the form inputs
document.getElementById('username').value = '';
document.getElementById('email').value = '';
document.getElementById('message').value = '';
} else {
alert('Please fill out all fields.');
}
});
// Retrieve and log all messages stored in localStorage
function logStoredMessages() {
let storedMessages = JSON.parse(localStorage.getItem('messages')) || [];
storedMessages.forEach((msg, index) => {
console.log(`Message ${index + 1}`);
console.log('Name:', msg.username);
console.log('Email:', msg.email);
console.log('Message:', msg.message);
});
}
// Call the function to log stored messages when the page loads
logStoredMessages();
});