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

77
Views
JS parallax effect / only usable for Images/Elements that are not positioned at the top

I'm currently trying to create a lightweight parallax effect in JS. The only problem that i'm running into is, when i try to assign the effect to elements mid-document. Here's the current code:

[].forEach.call(document.getElementsByClassName('parallax'), function (v) {
    window.addEventListener('scroll', function () {
        let eTop = $('parallax').offset();
        let value = window.scrollY;
        v.style.top = value * .5 + 'px';
    });
});

If i now assign the 'parallax' class to objects below the top position they get weirdly transformed because their respective position is calculated using window.scollY resulting in heavily transformed positions. I guess the best way to deal with it is to subtract the elements actual position on the document, right? And if so how to do it? (newbie here)

Thamks in advance!

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