146 lines
4.4 KiB
JavaScript
146 lines
4.4 KiB
JavaScript
// Menu effects
|
|
|
|
jQuery(document).scroll(function() {
|
|
var y = jQuery(this).scrollTop();
|
|
|
|
if (y > 100) {
|
|
jQuery('.front .navbar').removeClass('bg-transparent').addClass('bg-white');
|
|
jQuery('.front .navbar-brand').removeClass('d-none');
|
|
} else {
|
|
jQuery('.front .navbar').removeClass('bg-white').addClass('bg-transparent');
|
|
}
|
|
});
|
|
|
|
// Frontpage effects
|
|
|
|
jQuery(document).scroll(function() {
|
|
var y = jQuery(this).scrollTop();
|
|
|
|
if (y > 500) {
|
|
jQuery('#section-1-bis').addClass('pt-150');
|
|
} else {
|
|
jQuery('#section-1-bis').removeClass('pt-150');
|
|
}
|
|
});
|
|
|
|
jQuery(document).ready(function($) {
|
|
|
|
var scrollDown = $(".scrolldown-1"),
|
|
topElementHeight = 0,
|
|
elementItems = scrollDown.find("a"),
|
|
scrollItems = elementItems.map(function(){
|
|
var item = $($(this).attr("href"));
|
|
if (item.length) { return item; }
|
|
});
|
|
|
|
elementItems.click(function(e){
|
|
var href = $(this).attr("href"),
|
|
offsetTop = href === "#" ? 0 : $(href).offset().top-topElementHeight+1;
|
|
$('html, body').stop().animate({
|
|
scrollTop: offsetTop
|
|
}, 600);
|
|
e.preventDefault();
|
|
});
|
|
|
|
$('.carousel').carousel()
|
|
|
|
$('.embed-responsive iframe').addClass('embed-responsive-item')
|
|
|
|
// Calcular ancho columnas carrousel portada
|
|
//~ var colwidth = $( window ).width();
|
|
//~ if (colwidth <= 414) {
|
|
//~ $('#projectsSliderXs').removeClass('d-none');
|
|
//~ $('#projectsSliderMd').addClass('d-none');
|
|
//~ $('#projectsSliderLg').addClass('d-none');
|
|
//~ $('#frontpage-actualidad-xs').removeClass('d-none');
|
|
//~ $('#frontpage-actualidad-md').addClass('d-none');
|
|
//~ $('#frontpage-actualidad-lg').addClass('d-none');
|
|
//~ } else if (colwidth <= 1024) {
|
|
//~ $('#projectsSliderXs').addClass('d-none');
|
|
//~ $('#projectsSliderMd').removeClass('d-none');
|
|
//~ $('#projectsSliderLg').addClass('d-none');
|
|
//~ $('#frontpage-actualidad-xs').addClass('d-none');
|
|
//~ $('#frontpage-actualidad-md').removeClass('d-none');
|
|
//~ $('#frontpage-actualidad-lg').addClass('d-none');
|
|
//~ } else {
|
|
//~ $('#projectsSliderXs').addClass('d-none');
|
|
//~ $('#projectsSliderMd').addClass('d-none');
|
|
//~ $('#projectsSliderLg').removeClass('d-none');
|
|
//~ $('#frontpage-actualidad-xs').addClass('d-none');
|
|
//~ $('#frontpage-actualidad-md').addClass('d-none');
|
|
//~ $('#frontpage-actualidad-lg').removeClass('d-none');
|
|
//~ }
|
|
|
|
});
|
|
|
|
// Función para animar un contador individual
|
|
function animateCounter(element, target, duration = 2000) {
|
|
const start = 0;
|
|
const increment = target / (duration / 16); // 60 FPS
|
|
let current = start;
|
|
|
|
const timer = setInterval(() => {
|
|
current += increment;
|
|
if (current >= target) {
|
|
element.textContent = target.toLocaleString();
|
|
clearInterval(timer);
|
|
} else {
|
|
element.textContent = Math.floor(current).toLocaleString();
|
|
}
|
|
}, 16);
|
|
}
|
|
|
|
// Función para iniciar todos los contadores
|
|
function startCounters() {
|
|
const counters = document.querySelectorAll('.counter');
|
|
|
|
counters.forEach((counter, index) => {
|
|
const target = parseInt(counter.getAttribute('data-target'));
|
|
|
|
// Añadir un pequeño retraso entre cada contador para un efecto escalonado
|
|
setTimeout(() => {
|
|
animateCounter(counter, target);
|
|
}, index * 200);
|
|
});
|
|
}
|
|
|
|
// Configurar el Intersection Observer
|
|
const observer = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
// Añadir clase de animación al contenedor
|
|
entry.target.classList.add('animate');
|
|
|
|
// Iniciar contadores después de un pequeño retraso
|
|
setTimeout(() => {
|
|
startCounters();
|
|
}, 300);
|
|
|
|
// Dejar de observar una vez que se ha activado
|
|
observer.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.3, // Se activa cuando el 30% del elemento es visible
|
|
rootMargin: '-50px' // Margen adicional para un mejor control
|
|
});
|
|
|
|
// Iniciar la observación cuando el DOM esté listo
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const counterContainer = document.getElementById('counterContainer');
|
|
observer.observe(counterContainer);
|
|
});
|
|
|
|
// Función opcional para reiniciar los contadores (útil para testing)
|
|
function resetCounters() {
|
|
const counters = document.querySelectorAll('.counter');
|
|
counters.forEach(counter => {
|
|
counter.textContent = '0';
|
|
});
|
|
|
|
const container = document.getElementById('counterContainer');
|
|
container.classList.remove('animate');
|
|
|
|
// Reiniciar la observación
|
|
observer.observe(container);
|
|
} |