(function () {
const SECTIONS = [
{ class: 'higia-bg-1', color: '#011489' }, // Medicina Eficiencia
{ class: 'higia-bg-2', color: '#606db2' }, // TDH
{ class: 'higia-bg-3', color: '#9edba0' }, // AB
{ class: 'higia-bg-4', color: '#ea9486' }, // Psicología
{ class: 'higia-bg-5', color: '#f4b17f' } // TAI
];
function init() {
const elements = SECTIONS.map(item => ({
...item,
el: document.querySelector('.' + item.class)
}));
function onScroll() {
const mid = window.scrollY + (window.innerHeight / 2);
for (let s of elements) {
if (!s.el) continue;
const rect = s.el.getBoundingClientRect();
const top = rect.top + window.scrollY;
const bottom = rect.bottom + window.scrollY;
if (mid >= top && mid <= bottom) {
document.documentElement.style.setProperty('--higia-bg-color', s.color);
break;
}
}
}
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('load', onScroll);
onScroll();
}
let tries = 0;
const interval = setInterval(function () {
tries++;
if (document.querySelector('.higia-bg-1')) {
clearInterval(interval);
init();
}
if (tries > 50) {
clearInterval(interval);
}
}, 200);
})();