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

405
Views
Vincular la transformación de translateX () en Angular 2+

¿Cómo se puede vincular el estilo transform: translateX() en Angular?

Lo que he probado:

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

y

 <div [style.transform.translateX.px]="x">
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Esto debería funcionar

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

Editar

Parece que es necesario eludir la protección XSS para que esto funcione.

about 4 years ago · Santiago Trujillo Report

0

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

donde transX es una variable componente.

about 4 years ago · Santiago Trujillo Report

0

La respuesta aceptada funciona, pero puede hacer que su código sea mucho más limpio utilizando métodos como enlace de sus propiedades de estilo.

 <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>

En la clase que contiene los valores a los que debe vincularse:

 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 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!