-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (74 loc) · 3.27 KB
/
script.js
File metadata and controls
104 lines (74 loc) · 3.27 KB
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
// script.js
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('year').textContent = new Date().getFullYear();
document.querySelectorAll('nav a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
window.scrollTo({
top: targetElement.offsetTop - 70,
behavior: 'smooth'
});
});
});
const filterButtons = document.querySelectorAll('.filter-btn');
const portfolioItems = document.querySelectorAll('.portfolio-item');
filterButtons.forEach(button => {
button.addEventListener('click', function() {
filterButtons.forEach(btn => btn.classList.remove('active'));
this.classList.add('active');
const filterValue = this.getAttribute('data-filter');
portfolioItems.forEach(item => {
if (filterValue === 'all' || item.getAttribute('data-category') === filterValue) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
});
});
const statNumbers = document.querySelectorAll('.number');
function animateStats() {
statNumbers.forEach(number => {
const target = +number.getAttribute('data-target');
const count = +number.innerText;
const increment = target / 100;
if (count < target) {
number.innerText = Math.ceil(count + increment);
setTimeout(animateStats, 20);
} else {
number.innerText = target + '+';
}
});
}
const statsSection = document.querySelector('.about-stats');
function checkStatsInView() {
const sectionTop = statsSection.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (sectionTop < windowHeight - 100) {
animateStats();
window.removeEventListener('scroll', checkStatsInView);
}
}
window.addEventListener('scroll', checkStatsInView);
checkStatsInView();
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
alert('Thank you for your message! I will get back to you soon.');
this.reset();
});
}
const header = document.querySelector('header');
window.addEventListener('scroll', function() {
if (window.scrollY > 100) {
header.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
header.style.padding = '10px 0';
} else {
header.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
header.style.padding = '20px 0';
}
});
});