Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!