Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda