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

148
Visualizações
on scroll function is only calling 1 function

am trying to add sticky tag to side Divs and am calling javascript for this, when am calling the function more than once in the same page only 1 div is affected and when i tried to make it 2 different functions for 2 different Divs is only calling the last function and skipping the other

<script>
    window.onscroll = function() {
      myFunctionR();
      myFunctionL();
    }

    var header = document.getElementById("stickDivL");
    var header = document.getElementById("stickDivR");
    var sticky = header.offsetTop;

    function myFunctionL() {
      var scrollDivL =  window.pageYOffset;  
      if (scrollDivL > sticky) {
        header.classList.add("sticky");
        header.classList.add("col-xl-3");
        header.classList.remove("col-xl-12");
      } else {
        header.classList.remove("sticky");
        header.classList.remove("col-xl-3");
        header.classList.add("col-xl-12");
      }
      
    };

    function myFunctionR() {
      var scrollDivR =  window.pageYOffset;  
      if (scrollDivR > sticky) {
        header.classList.add("sticky");
        header.classList.add("col-xl-3");
        header.classList.remove("col-xl-12");
      } else {
        header.classList.remove("sticky");
        header.classList.remove("col-xl-3");
        header.classList.add("col-xl-12");
      }
      
    };
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're assigning both values ​​to only 1 variable try this

var header0 = document.getElementById("stickDivL");
var header1 = document.getElementById("stickDivR");

it happens because when you call var header = document.getElementById("stickDivR"); you're overwriting the variable.

like

var Foo1 = 1
var Foo1 = 10
console.log(Foo1)

you'll see 10

about 4 years ago · Juan Pablo Isaza Relatório
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