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

239
Views
Problem with the '.style.transform=' in JS

I have this SVG header that, on screen scroll, its parts move differently. For this, I am using a script like the following:

let menu = document.getElementById('main-menu');
let lua = document.getElementById('lua');
            
    window.addEventListener('scroll', function(){
        let value = window.scrollY;
        menu.style.marginTop = value * 0.45 + 'px'; // working just fine
        lua.style.transform = "translateY(" + value * 0.25 + ")"; // don't know how to make this work

OBS: I need to use the transform: translate because this SVG element, for some reason, can't be moved with margin or top/left, only translate.

The menu.style work just fine, but on the lua.style case I'm struggling cause I don't know how to write on the JS a CSS such as transform: translateY that merges a child property (translate) inside another property (transform).

I've tried to write the lua.style.transform = "translateY(" + value * 0.25 + ")"; in many different ways, like:

lua.style.transform = value + "translateY(" * 0.25 + ")";
// or
lua.style.translate = value * 0.45 + 'px';
// or
lua.style.translate = value * 0.45;
// or
lua.style.translate = (0,value * 0.45);

but still can't make it work. How can I write it correctly?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

DONE! I used the template literal that Dane Landry explained in the comments. Thanks man.

The code:

lua.style.transform = ` translateY(${value * 0.25}px ) `;

And also thanks kmoser for reminding me translate demans a unit of measurement. It does.

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!