Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda