Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
Conflict between multiple instances of (window).scroll

I have multiple instances of (window).scroll function that are problematic at times. Is there a way I can separate them so that these do not conflict with each other?

First instance that appears on every page:

$(window).scroll(function(){
    if ($(this).scrollTop() > 50) {
        $('.gotop').addClass('gotop-visible');
    } else {
        $('.gotop').removeClass('gotop-visible');
    }
});

The second instance only appears on one page but is repeated several times for various classes while the first instance is also present:

$(window).scroll(function(){
    var light_pos = $('.dark main').offset().top;
    var light_height = $('.dark main').height();
    var menu_pos = $('.top-left h1').offset().top;
    var menu_height = $('.top-left h1').height();
    if(menu_pos > light_pos && menu_pos < (light_pos + light_height)) {
        $('.top-left h1').addClass('menu_black');
        $('.top-left h1').removeClass('menu_white');
    }
    else {
        $('.top-left h1').removeClass('menu_black');
        $('.top-left h1').addClass('menu_white');
    }
})

Is there a way these functions can be separated clearly?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda