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

153
Vistas
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 Respuestas
Responde la pregunta

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 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