-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
80 lines (67 loc) · 2.27 KB
/
main.js
File metadata and controls
80 lines (67 loc) · 2.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
const arrow = document.getElementById("next-arrow");
const sections = document.querySelectorAll("section[id]");
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const next = entry.target.getAttribute("data-next");
if (next) {
arrow.href = next;
arrow.classList.remove("hidden");
} else {
arrow.classList.add("hidden");
}
}
});
}, {
threshold: 0.6
});
sections.forEach(section => observer.observe(section));
function smoothScrollTo(target, duration = 1500) {
const start = window.scrollY;
const end = target.getBoundingClientRect().top + window.scrollY;
const distance = end - start;
const startTime = performance.now();
function easeInOutQuad(t) {
return t < 0.5 ? 2*t*t : -1+(4-2*t)*t;
}
function scroll(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const eased = easeInOutQuad(progress);
window.scrollTo(0, start + distance * eased);
if (elapsed < duration) {
requestAnimationFrame(scroll);
}
}
requestAnimationFrame(scroll);
}
document.querySelectorAll('a.scroll-link[href^="#"]').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const target = document.querySelector(targetId);
if (target) {
console.log(target)
smoothScrollTo(target, 1500); // můžeš si upravit čas v ms
}
});
});
function resizeSVG() {
const totalHeight = document.body.scrollHeight;
const svg = document.getElementById('svg-path');
svg.style.height = `${totalHeight}px`;
svg.setAttribute('viewBox', `0 0 1000 ${totalHeight}`);
}
function updateParallax() {
const svgBg = document.getElementById('svg-bg');
const scrollY = window.scrollY;
// Parallax efekt: čím větší číslo, tím pomalejší posun
svgBg.style.transform = `translateY(${scrollY * 0.3}px)`;
}
// Při načtení a resize
window.addEventListener('load', () => {
resizeSVG();
updateParallax();
});
window.addEventListener('resize', resizeSVG);
window.addEventListener('scroll', updateParallax);