-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (82 loc) · 3.98 KB
/
script.js
File metadata and controls
97 lines (82 loc) · 3.98 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
document.addEventListener('DOMContentLoaded', () => {
// ─── SCROLL: NAVBAR SHRINK ───────────────────────────────────────────────
const topnav = document.getElementById('topnav');
window.addEventListener('scroll', () => {
if (window.scrollY > 40) {
topnav.classList.add('scrolled');
} else {
topnav.classList.remove('scrolled');
}
});
// ─── SMOOTH SCROLL ───────────────────────────────────────────────────────
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = topnav.offsetHeight + 16;
const top = target.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top, behavior: 'smooth' });
}
});
});
// ─── THEME TOGGLE ────────────────────────────────────────────────────────
const themeBtn = document.getElementById('themeBtn');
const sunIcon = document.getElementById('sunIcon');
const moonIcon = document.getElementById('moonIcon');
const html = document.documentElement;
const savedTheme = localStorage.getItem('theme') || 'dark';
applyTheme(savedTheme);
themeBtn.addEventListener('click', () => {
const current = html.getAttribute('data-theme');
applyTheme(current === 'dark' ? 'light' : 'dark');
});
function applyTheme(theme) {
html.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
if (theme === 'dark') {
sunIcon.style.display = 'block';
moonIcon.style.display = 'none';
} else {
sunIcon.style.display = 'none';
moonIcon.style.display = 'block';
}
}
// ─── LANGUAGE TOGGLE ─────────────────────────────────────────────────────
const langBtn = document.getElementById('langBtn');
const langLabel = document.getElementById('langLabel');
let currentLang = localStorage.getItem('lang') || 'tr';
applyLang(currentLang);
langBtn.addEventListener('click', () => {
currentLang = currentLang === 'tr' ? 'en' : 'tr';
applyLang(currentLang);
});
function applyLang(lang) {
localStorage.setItem('lang', lang);
langLabel.textContent = lang.toUpperCase();
// Translate all elements that have data-tr and data-en
document.querySelectorAll('[data-tr]').forEach(el => {
const text = el.getAttribute('data-' + lang);
if (text) el.innerHTML = text;
});
// Update html lang attribute
document.documentElement.lang = lang;
}
// ─── SCROLL ANIMATIONS ───────────────────────────────────────────────────
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.hero-content, .portrait-container, .glass-header, .about-text, .project-card, .social-links, .cv-button').forEach(el => {
el.classList.add('hidden');
observer.observe(el);
});
});