Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
JQuery, run function one at a time on scroll

So, I bind a function to window scroll, but it runs repeatedly when user scrolls.

But I want it to run once when user scrolls, and when the scroll ends, then when user scrolls again I want it to run again.

Right now my code looks like this:

function whenScroll() {
    var zSection = $(".zSection").toArray();

    if (window.calc == -1) {
        $(zSection[window.zSecPos]).stop().slideToggle();
    } else {
        $(zSection[window.zSecPos-1]).stop().slideToggle();
    }
    clearTimeout($.data(this, "scrollTimer"));
    $.data(this, "scrollTimer", setTimeout(function() {
        if (window.calc == -1) {
            window.zSecPos = window.zSecPos + 1;
        } else {
            window.zSecPos = window.zSecPos - 1;
        }
    }, 250));
}

window.zSecPos = 0;
$(window).scroll(function() {
    whenScroll();
});

By the way, window.calc indicates the scroll direction, which I determine in another js file.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I ended up fixing it myself. Sorry.

The thing is I have seperate all page long sections, which I want to scroll through between them.

So, my final code:

function whenScroll() {
    var zSection = $(".zSection").toArray();

    clearTimeout($.data(this, "scrollTimer"));
    $.data(this, "scrollTimer", setTimeout(function() {
        if (window.calc == -1) {
            if ($(zSection[window.zSecPos+1]).length) {
                $(zSection[window.zSecPos]).stop().animate({
                    top: "-100vh"
                }, 300);
                window.zSecPos = window.zSecPos + 1;
            }
        } else {
            if ($(zSection[window.zSecPos-1]).length) {
                $(zSection[window.zSecPos-1]).stop().animate({
                    top: "0"
                }, 300);
                window.zSecPos = window.zSecPos - 1;
            }
        }
        console.log(window.zSecPos);
    }, 300));
}

$(document).ready(function() {
    setTimeout(function() {
        $(".zSection").removeClass("displayNone");
    }, 1000);
});

window.zSecPos = 0;
$(window).scroll(function() {
    whenScroll();
});
about 4 years ago · Juan Pablo Isaza Denunciar
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda