13 lines
578 B
JavaScript
13 lines
578 B
JavaScript
// Resalta en el índice de la ideología el principio que se está leyendo. Sin dependencias.
|
|
(() => {
|
|
const enlaces = document.querySelectorAll('.indice a');
|
|
if (enlaces.length && 'IntersectionObserver' in window) {
|
|
const obs = new IntersectionObserver(entradas => {
|
|
entradas.forEach(en => {
|
|
if (!en.isIntersecting) return;
|
|
enlaces.forEach(a => a.classList.toggle('activo', a.hash === '#' + en.target.id));
|
|
});
|
|
}, { rootMargin: '-30% 0px -60% 0px' });
|
|
document.querySelectorAll('.principio').forEach(p => obs.observe(p));
|
|
}
|
|
})();
|