• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

135
Vistas
Can't check if the code is in the viewport

this is a code to detect if the section which I'm scrolling right now is in the viewport or not. This code actually works only if I get onto any section and refresh the page, it doesn't work continuously when I scroll through the page.

var secArr = document.querySelectorAll('section');


secArr.forEach(onscroll = function (element) {
    var bounding = element.getBoundingClientRect();

    if (bounding.top <= 350.00 && bounding.top >= -270.00) {
        if (!element.classList.contains("your-active-class")) {
            element.setAttribute("class", "your-active-class");
        }
    } 
    else {
        element.removeAttribute("class");
    }
});
almost 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda