-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
76 lines (68 loc) · 2.51 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
// Function to handle card tilt effect
function setupCardTiltEffect(cards) {
cards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const xAxis = (window.innerWidth / 2 - e.pageX) / 25;
const yAxis = (window.innerHeight / 2 - e.pageY) / 25;
card.style.transform = `rotateY(${xAxis}deg) rotateX(${yAxis}deg)`;
});
card.addEventListener('mouseenter', () => {
card.style.transition = 'none';
card.style.transform = `translateZ(55px)`;
});
card.addEventListener('mouseleave', () => {
card.style.transition = 'all 0.4s ease';
card.style.transform = `rotateY(0deg) rotateX(0deg) translateZ(0)`;
});
});
}
// Function for smooth scrolling
function setupSmoothScrolling(links) {
links.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
document.querySelector(link.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
}
// Function to handle layout change on window resize
function setupResponsiveLayout() {
const projectSection = document.getElementById('projects');
const updateLayout = () => {
projectSection.style.display = window.innerWidth < 770 ? 'block' : 'flex';
projectSection.style.flexDirection = window.innerWidth < 770 ? 'column' : 'row';
projectSection.style.justifyContent = 'center';
};
window.addEventListener('resize', updateLayout);
updateLayout(); // Call once to set initial layout
}
// Function to setup theme toggler
function setupThemeToggler() {
const toggleButton = document.createElement('button');
toggleButton.textContent = 'Toggle Theme';
Object.assign(toggleButton.style, {
position: 'fixed',
bottom: '20px',
right: '20px',
padding: '10px 15px',
backgroundColor: '#61dafb',
color: '#fff',
border: 'none',
cursor: 'pointer'
});
document.body.appendChild(toggleButton);
toggleButton.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
});
}
// Initialize all functionalities
document.addEventListener('DOMContentLoaded', () => {
const projectCards = document.querySelectorAll('#projects div');
const navLinks = document.querySelectorAll('nav ul li a');
setupCardTiltEffect(projectCards);
setupSmoothScrolling(navLinks);
setupResponsiveLayout();
setupThemeToggler();
});