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

406
Visualizações
Bind translateX() transform in Angular 2+

How can one bind the transform: translateX() style in Angular?

What I've tried:

<div [style.transform]="translateX({{x}})">

and

<div [style.transform.translateX.px]="x">
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

This should work

<div [style.transform]="'translateX(' + x + 'px)'">

Edit

It seems that it is necessary to bypass XSS protection for this to work.

about 4 years ago · Santiago Trujillo Relatório

0

[ngStyle]="{'transform': 'translateX(' + transX + 'px)'}"

where transX is a component variable.

about 4 years ago · Santiago Trujillo Relatório

0

The accepted answer works but you can make you code a lot cleaner by using methods as the binding of your style properties

<div *ngFor="let il of imageLayers">
    <img class="divFloatLayer" 
        [src]="il.img_src" 
        [style.left]="il.getLeftPx()"
        [style.top]="il.getTopPx()"
        [style.z-index]="il.getZindex()"
        [style.transform]="il.getTransform()"
    />
</div>

In the class that contains the values that you need to bind to:

getLeftPx() {
    return `${this.left}px` ;
}

getTopPx() {
    return `${this.top}px` ;
}

getZindex() {
    return `${this.z_index}` ;
}

getTransform() {
    return `translateX(${this.x}px)`;
}
about 4 years ago · Santiago Trujillo 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