estoy tratando de agregar una etiqueta adhesiva a los Divs laterales y estoy llamando a javascript para esto, cuando llamo a la función más de una vez en la misma página, solo 1 div se ve afectado y cuando traté de hacer 2 funciones diferentes para 2 Divs diferentes solo está llamando la última función y saltándose la otra
<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>Estás asignando ambos valores a solo 1 variable, prueba esto
var header0 = document.getElementById("stickDivL"); var header1 = document.getElementById("stickDivR"); sucede porque cuando llamas a var header = document.getElementById("stickDivR"); estás sobrescribiendo la variable.
me gusta
var Foo1 = 1 var Foo1 = 10 console.log(Foo1) verás 10