-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
228 lines (195 loc) · 7.6 KB
/
script.js
File metadata and controls
228 lines (195 loc) · 7.6 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// JavaScript para funcionalidades interativas
document.addEventListener('DOMContentLoaded', function() {
// Funcionalidade de busca
const searchInput = document.querySelector('.search-box input');
const searchIcon = document.querySelector('.search-box i');
searchIcon.addEventListener('click', function() {
performSearch();
});
searchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
performSearch();
}
});
function performSearch() {
const query = searchInput.value.trim();
if (query) {
alert(`Buscando por: "${query}"`);
// Aqui você implementaria a lógica real de busca
}
}
// Animação suave ao rolar para links internos
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'
});
}
});
});
// Efeito hover nas notícias
const newsItems = document.querySelectorAll('.news-item h4, .story-item h3');
newsItems.forEach(item => {
item.addEventListener('click', function() {
// Simulação de clique em notícia
console.log('Notícia clicada:', this.textContent);
});
});
// Funcionalidade dos botões de serviço
const serviceButtons = document.querySelectorAll('.service-btn');
serviceButtons.forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
const serviceName = this.closest('.service-card').querySelector('h4').textContent;
alert(`Redirecionando para ${serviceName}...`);
});
});
// Botões de login e assinatura
const loginBtn = document.querySelector('.login-btn');
const subscribeBtn = document.querySelector('.subscribe-btn');
if (loginBtn) {
loginBtn.addEventListener('click', function() {
alert('Redirecionando para área de login...');
});
}
if (subscribeBtn) {
subscribeBtn.addEventListener('click', function() {
alert('Redirecionando para área de assinatura...');
});
}
// Atualização dinâmica do horário nas notícias
function updateNewsTimes() {
const timeElements = document.querySelectorAll('.story-time, .news-time');
timeElements.forEach(element => {
// Simulação de atualização de tempo
// Em um cenário real, isso viria de uma API
});
}
// Função para simular carregamento de mais notícias
function loadMoreNews() {
console.log('Carregando mais notícias...');
// Aqui você implementaria a lógica para carregar mais conteúdo
}
// Detecção de scroll para lazy loading (se necessário)
let lastScrollTop = 0;
window.addEventListener('scroll', function() {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
// Verificar se chegou próximo ao final da página
if ((window.innerHeight + scrollTop) >= document.body.offsetHeight - 1000) {
// Implementar lazy loading aqui se necessário
}
lastScrollTop = scrollTop;
});
// Menu mobile (se expandir para incluir menu hamburger)
function createMobileMenu() {
if (window.innerWidth <= 768) {
// Lógica para menu mobile
const nav = document.querySelector('.main-nav');
if (nav && !nav.classList.contains('mobile-ready')) {
nav.classList.add('mobile-ready');
// Adicionar funcionalidades mobile
}
}
}
// Verificar tamanho da tela ao redimensionar
window.addEventListener('resize', function() {
createMobileMenu();
});
// Inicializar menu mobile se necessário
createMobileMenu();
// Funcionalidade para dark mode (opcional)
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
localStorage.setItem('darkMode', document.body.classList.contains('dark-mode'));
}
// Carregar preferência de dark mode
if (localStorage.getItem('darkMode') === 'true') {
document.body.classList.add('dark-mode');
}
// Animação de entrada para elementos
function animateOnScroll() {
const elements = document.querySelectorAll('.news-category, .service-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
elements.forEach(element => {
element.style.opacity = '0';
element.style.transform = 'translateY(20px)';
element.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(element);
});
}
// Inicializar animações
animateOnScroll();
// Simulação de dados dinâmicos
function updateDynamicContent() {
// Atualizar cotações (simulação)
const currencies = document.querySelectorAll('.currency');
currencies.forEach(currency => {
// Em um cenário real, isso viria de uma API de cotações
if (currency.textContent.includes('Dólar')) {
const variation = (Math.random() - 0.5) * 0.1;
const currentValue = 5.545 + variation;
currency.textContent = `Dólar ${currentValue.toFixed(3)}`;
}
});
}
// Atualizar conteúdo dinâmico a cada 30 segundos
setInterval(updateDynamicContent, 30000);
// Adicionar funcionalidade de compartilhamento social
function addShareButtons() {
const newsItems = document.querySelectorAll('.news-item, .story-item');
newsItems.forEach(item => {
item.addEventListener('contextmenu', function(e) {
e.preventDefault();
// Mostrar opções de compartilhamento
console.log('Opções de compartilhamento para:', item.querySelector('h3, h4').textContent);
});
});
}
addShareButtons();
console.log('UOL Landing Page carregada com sucesso!');
});
// Função utilitária para formatar datas
function formatDate(date) {
const now = new Date();
const diff = now - date;
const minutes = Math.floor(diff / 60000);
const hours = Math.floor(diff / 3600000);
if (minutes < 60) {
return `Há ${minutes} min`;
} else if (hours < 24) {
return `Há ${hours} hora${hours > 1 ? 's' : ''}`;
} else {
return date.toLocaleDateString('pt-BR');
}
}
// Função para validar email (se implementar newsletter)
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
// Service Worker para PWA (opcional)
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js')
.then(function(registration) {
console.log('SW registrado com sucesso:', registration.scope);
})
.catch(function(registrationError) {
console.log('Falha no registro do SW:', registrationError);
});
});
}