-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
94 lines (82 loc) · 2.51 KB
/
script.js
File metadata and controls
94 lines (82 loc) · 2.51 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
document.addEventListener('DOMContentLoaded', () => {
const createObserver = (elements, callback, options = { threshold: 0.2 }) => {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
callback(entry.target);
observer.unobserve(entry.target);
}
});
}, options);
elements.forEach((element) => observer.observe(element));
};
window.addEventListener('scroll', function () {
dataLayer.push({
event: 'scroll',
scrollPercent: Math.round(
(window.scrollY /
(document.documentElement.scrollHeight - window.innerHeight)) *
100,
),
});
});
window.addEventListener('gtm.load', function (event) {
console.log('Container Loaded:', event.detail.containerId);
});
const activateElement = (element) => {
element.classList.add('active');
};
const initProjectAnimations = () => {
const projetos = document.querySelectorAll('.projeto');
if (projetos.length > 0) {
createObserver(projetos, activateElement);
}
};
const initTestimonialAnimation = () => {
const testimonial = document.querySelector('.testimonials blockquote');
if (testimonial) {
testimonial.classList.add('hidden');
createObserver([testimonial], activateElement);
}
};
const scrollToPosition = (position) => {
window.scrollTo({
top: position,
behavior: 'smooth',
});
};
const initLogoScroll = () => {
const logo = document.getElementById('logo');
if (logo) {
logo.addEventListener('click', (event) => {
event.preventDefault();
scrollToPosition(0);
});
}
};
const initGitHubButtons = () => {
const gitHubButtons = document.querySelectorAll('.button-primary');
gitHubButtons.forEach((button) => {
button.addEventListener('click', (event) => {
event.stopPropagation(); // Previne que o evento clique se propague para elementos pais
});
});
};
initProjectAnimations();
initTestimonialAnimation();
initLogoScroll();
initGitHubButtons();
});
document.getElementById('currentYear').textContent = new Date().getFullYear();
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start',
});
}
});
});